-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathccc05j4.cpp
78 lines (70 loc) · 1.7 KB
/
ccc05j4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <bits/stdc++.h>
using namespace std;
vector<vector<bool>> arr;
int k;
void sset(int x, int y)
{
arr[x][y] = true;
--k;
}
void moveDown(int &x, int &y)
{
while (k && x+1 < arr.size() && !arr[x+1][y])
sset(x, y), ++x;
}
void moveRight(int &x, int &y)
{
while (k && y+1 < arr[0].size() && !arr[x][y+1])
sset(x, y), ++y;
}
void moveLeft(int &x, int &y)
{
while (k && y-1 >= 0 && !arr[x][y-1])
sset(x, y), --y;
}
void moveUp(int &x, int &y)
{
while (k && x-1 >= 0 && !arr[x-1][y])
sset(x, y), --x;
}
int main()
{
int n, m, o, p;
scanf("%i%i%i%i", &m, &n, &p, &o);
arr.resize(n, vector<bool>(m));
for (int x = 0; x < o; x++)
{
for (int y = 0; y < p; y++)
{
arr[x][y] = true;
arr[x][m-y-1] = true;
arr[n-x-1][y] = true;
arr[n-x-1][m-y-1] = true;
}
}
scanf("%i", &k);
int x = 0, y = p;
while (k)
{
int xx = x, yy = y;
moveRight(x, y);
while (k && x+1 < arr.size() && !arr[x+1][y] && (y+1 == arr[0].size() || arr[x][y+1]))
sset(x, y), ++x;
moveRight(x, y);
moveDown(x, y);
while (k && y-1 >= 0 && !arr[x][y-1] && (x+1 == arr.size() || arr[x+1][y]))
sset(x, y), --y;
moveDown(x, y);
moveLeft(x, y);
while (k && x-1 >= 0 && !arr[x-1][y] && (y-1 < 0 || arr[x][y-1]))
sset(x, y), --x;
moveLeft(x, y);
moveUp(x, y);
while (k && y+1 < arr[0].size() && !arr[x][y+1] && (x-1 < 0 || arr[x-1][y]))
sset(x, y), ++y;
moveUp(x, y);
if (xx == x && yy == y)
break;
}
printf("%i\n%i\n", y+1, x+1);
}