# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90356 | Hideo | Ants (IZhO12_ants) | C++14 | 2 ms | 648 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define mk make_pair
#define fir first
#define sec second
#define eq ((d[i] + 1) % 4 + 1)
const int N = 105;
const int INF = 1e9 + 7;
int us[N][N][4], skp[N];
pair < int, int > a[N], o[N];
int d[N];
int w, h, k, t;
main(){
cin >> w >> h >> k >> t;
for (int i = 0; i < k; i++){
int x, y, z;
scanf ("%d%d%d", &x, &y, &z);
a[i] = make_pair(x, y);
d[i] = z;
us[a[i].fir][a[i].sec][d[i]] = i + 1;
if (d[i] == 1){
if (us[a[i].fir + 1][a[i].sec][eq] - 1 != -1){
d[i] = 3;
skp[i] = 1;
skp[us[a[i].fir + 1][a[i].sec][3] - 1] = 1;
d[us[a[i].fir + 1][a[i].sec][3] - 1] = 1;
}
}
else if (d[i] == 2){
if (us[a[i].fir][a[i].sec + 1][eq] - 1 != -1){
d[i] = 4;
skp[i] = 1;
skp[us[a[i].fir][a[i].sec + 1][4] - 1] = 1;
d[us[a[i].fir][a[i].sec + 1][4] - 1] = 2;
}
}
else if (d[i] == 3){
if (us[a[i].fir - 1][a[i].sec][eq] - 1 != -1){
d[i] = 1;
skp[i] = 1;
skp[us[a[i].fir - 1][a[i].sec][1] - 1] = 1;
d[us[a[i].fir - 1][a[i].sec][1] - 1] = 3;
}
}
else if (d[i] == 4){
if (us[a[i].fir][a[i].sec - 1][eq] - 1 != -1){
d[i] = 2;
skp[i] = 1;
skp[us[a[i].fir][a[i].sec - 1][2] - 1] = 1;
d[us[a[i].fir][a[i].sec - 1][2] - 1] = 4;
}
}
}
int prv = 0;
while (t--){
for (int i = 0; i < k; i++){
if (skp[i] == 1){
skp[i] = 0;
continue;
}
int x = a[i].fir, y = a[i].sec;
int xo = x, yo = y;
us[x][y][d[i]] = 0;
if (d[i] == 1){
x++;
if (us[x + 1][y][eq] != 0 && us[x + 1][y][eq] - 1 < i){
swap (d[i], d[us[x + 1][y][eq] - 1]);
}
if (us[x][y][eq] != 0 && us[x][y][eq] - 1 < i){
swap (d[i], d[us[x][y][eq] - 1]);
}
if (x == w)
d[i] = 3;
}
else if (d[i] == 2){
y++;
if (us[x][y + 1][eq] != 0 && us[x][y + 1][eq] - 1 < i){
swap (d[i], d[us[x][y + 1][eq] - 1]);
}
if (us[x][y][eq] != 0 && us[x][y][eq] - 1 < i){
swap (d[i], d[us[x][y][eq] - 1]);
}
if (y == h)
d[i] = 4;
}
else if (d[i] == 3){
x--;
if (us[x - 1][y][eq] != 0 && us[x - 1][y][eq] - 1 < i){
swap (d[i], d[us[x - 1][y][eq] - 1]);
}
//cout << x << ' ' << y << ' ' << eq << ' ';
if (us[x][y][eq] != 0 && us[x][y][eq] - 1 < i){
swap (d[i], d[us[x][y][eq] - 1]);
}
if (x == 0)
d[i] = 1;
}
else if (d[i] == 4){
y--;
if (us[x][y - 1][eq] != 0 && us[x][y - 1][eq] - 1 < i){
swap (d[i], d[us[x][y - 1][eq] - 1]);
}
if (us[x][y][eq] != 0 && us[x][y][eq] - 1 < i){
swap (d[i], d[us[x][y][eq] - 1]);
}
if (y == 0)
d[i] = 2;
}
us[x][y][d[i]] = i + 1;
a[i].fir = x;
a[i].sec = y;
}
}
for (int i = 0; i < k; i++){
printf("%d %d %d\n", a[i].fir, a[i].sec, d[i]);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |