# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
90356 |
2018-12-21T10:33:23 Z |
Hideo |
Ants (IZhO12_ants) |
C++14 |
|
2 ms |
648 KB |
#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
ants.cpp:19:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
ants.cpp: In function 'int main()':
ants.cpp:69:17: warning: unused variable 'xo' [-Wunused-variable]
int xo = x, yo = y;
^~
ants.cpp:69:25: warning: unused variable 'yo' [-Wunused-variable]
int xo = x, yo = y;
^~
ants.cpp:61:9: warning: unused variable 'prv' [-Wunused-variable]
int prv = 0;
^~~
ants.cpp:23:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d%d", &x, &y, &z);
~~~~~~^~~~~~~~~~~~~~~~~~~~~~
ants.cpp:37:46: warning: array subscript is above array bounds [-Warray-bounds]
if (us[a[i].fir][a[i].sec + 1][eq] - 1 != -1){
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
ants.cpp:85:36: warning: array subscript is above array bounds [-Warray-bounds]
if (us[x][y + 1][eq] != 0 && us[x][y + 1][eq] - 1 < i){
~~~~~~~~~~~~~~~^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
372 KB |
Output is correct |
3 |
Correct |
2 ms |
408 KB |
Output is correct |
4 |
Correct |
2 ms |
452 KB |
Output is correct |
5 |
Correct |
2 ms |
516 KB |
Output is correct |
6 |
Incorrect |
2 ms |
648 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |