Submission #288980

# Submission time Handle Problem Language Result Execution time Memory
288980 2020-09-02T09:03:07 Z 반딧불(#5784) None (JOI12_rotate) C++17
10 / 100
138 ms 65540 KB
#include <bits/stdc++.h>

using namespace std;

struct Matrix{
    int i, j, dir; char c;
    int r=0, d=0;
    Matrix(){}
    Matrix(char c): c(c){}
};
vector<Matrix> Vec;

int n, q;
char arr[1005][1005];
char tmp[1005][1005];

int MA[4][1005];
void MakeMatrix(){
    vector<int> v[4];
    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];
    }
}

void rotateMatrix(int x, int y, int d){
    vector<int> 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;

    vector<int> corner2 = corner;
    vector<int> corner3;

    for(int i=1; i<=d; i++){
        vector<int> tmp;
        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++){
        vector<int> tmp;
        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];
    }
}

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];
    }
    MakeMatrix();

    while(q--){
        int x, y, d;
        scanf("%d %d %d", &x, &y, &d);
//        x = y = 1, d = n;
        rotateMatrix(x, y, d);
    }

    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

rotate.cpp: In function 'int main()':
rotate.cpp:78:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   78 |     scanf("%d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
rotate.cpp:80:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   80 |         scanf("%s", arr[i]+1);
      |         ~~~~~^~~~~~~~~~~~~~~~
rotate.cpp:95:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   95 |         scanf("%d %d %d", &x, &y, &d);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2168 KB Output is correct
2 Correct 5 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 137 ms 65540 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 134 ms 65536 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 138 ms 65540 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 135 ms 65540 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 131 ms 65540 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 135 ms 65540 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 136 ms 65540 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 130 ms 65536 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 133 ms 65536 KB Execution killed with signal 9