# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
288985 | 2020-09-02T09:09:50 Z | 반딧불(#5784) | None (JOI12_rotate) | C++17 | 1290 ms | 51516 KB |
#include <bits/stdc++.h> using namespace std; struct Matrix{ char c; int r=0, d=0; Matrix(){} Matrix(char c): c(c){} }; vector<Matrix> Vec; int n, q; char arr[1005][1005]; int MA[4][1005]; vector<int> corner, corner2, corner3, tmp, v[4]; int main(){ scanf("%d %d", &n, &q); for(int i=1; i<=n; i++){ scanf("%s", arr[i]+1); // for(int j=1; j<=n; j++) arr[i][j] = (i+j)%26+'a'; } for(int i=0; i<=n+1; i++){ for(int j=0; j<4; j++){ MA[j][i] = Vec.size(); Vec.push_back(Matrix(' ')); // Vec[MA[j][i]].dir = j, Vec[MA[j][i]].i = 0, Vec[MA[j][i]].j = i; } if(i) for(int j=0; j<4; j++) Vec[MA[j][i-1]].r = MA[j][i]; } for(int i=0; i<4; i++) v[i] = vector<int> (MA[i], MA[i]+n+2); for(int i=1; i<=n+1; i++){ for(int j=0; j<=n+1; j++){ Vec[v[0][j]].d = Vec.size(); Vec.push_back(Matrix(j ? arr[i][j] : ' ')); Vec[v[1][j]].d = Vec.size(); Vec.push_back(Matrix(j ? arr[n+1-j][i] : ' ')); Vec[v[2][j]].d = Vec.size(); Vec.push_back(Matrix(j ? arr[n+1-i][n+1-j] : ' ')); Vec[v[3][j]].d = Vec.size(); Vec.push_back(Matrix(j ? arr[j][n+1-i] : ' ')); for(int k=0; k<4; k++){ v[k][j] = Vec[v[k][j]].d; // Vec[v[k][j]].dir = k, Vec[v[k][j]].i = i, Vec[v[k][j]].j = j; } } for(int k=0; k<4; k++) for(int j=0; j<=n; j++) Vec[v[k][j]].r = v[k][j+1]; } while(q--){ int x, y, d; scanf("%d %d %d", &x, &y, &d); corner = {MA[0][y-1], MA[1][n+1-(x+d)], MA[2][n+1-(y+d)], MA[3][x-1]}; for(int z=0; z<x-1; z++) corner[0] = Vec[corner[0]].d; for(int z=0; z<y-1; z++) corner[1] = Vec[corner[1]].d; for(int z=0; z<n+1-(x+d); z++) corner[2] = Vec[corner[2]].d; for(int z=0; z<n+1-(y+d); z++) corner[3] = Vec[corner[3]].d; corner2 = corner; for(int i=1; i<=d; i++){ for(int k=0; k<4; k++) corner2[k] = Vec[corner2[k]].r; tmp = vector<int> {Vec[corner2[3]].d, Vec[corner2[0]].d, Vec[corner2[1]].d, Vec[corner2[2]].d}; for(int k=0; k<4; k++) Vec[corner2[k]].d = tmp[k]; } corner3 = corner2; for(int k=0; k<4; k++) corner2[k] = Vec[corner2[k]].r; for(int i=1; i<=d; i++){ for(int k=0; k<4; k++){ corner2[k] = Vec[corner2[k]].d, corner3[k] = Vec[corner3[k]].d; } for(int k=0; k<4; k++) Vec[corner3[k]].r = corner2[k]; } corner2 = corner; for(int i=1; i<=d; i++){ for(int k=0; k<4; k++) corner2[k] = Vec[corner2[k]].d; tmp = vector<int> {Vec[corner2[3]].r, Vec[corner2[0]].r, Vec[corner2[1]].r, Vec[corner2[2]].r}; for(int k=0; k<4; k++) Vec[corner2[k]].r = tmp[k]; } corner3 = corner2; for(int k=0; k<4; k++) corner2[k] = Vec[corner2[k]].d; for(int i=1; i<=d; i++){ for(int k=0; k<4; k++) corner2[k] = Vec[corner2[k]].r, corner3[k] = Vec[corner3[k]].r; for(int k=0; k<4; k++) Vec[corner3[k]].d = corner2[k]; } } for(int j=1; j<=n; j++){ int tmp = MA[0][j]; for(int i=1; i<=n; i++){ tmp = Vec[tmp].d; arr[i][j] = Vec[tmp].c; } } for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ printf("%c", arr[i][j]); } puts(""); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1404 KB | Output is correct |
2 | Correct | 4 ms | 1276 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 839 ms | 51516 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 918 ms | 51516 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 971 ms | 51516 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1018 ms | 51516 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1058 ms | 51516 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1166 ms | 51412 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1239 ms | 51516 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1242 ms | 51516 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1290 ms | 51516 KB | Output is correct |