Submission #90356

#TimeUsernameProblemLanguageResultExecution timeMemory
90356HideoAnts (IZhO12_ants)C++14
0 / 100
2 ms648 KiB
#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)

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 timeMemoryGrader output
Fetching results...