Submission #288948

# Submission time Handle Problem Language Result Execution time Memory
288948 2020-09-02T08:22:42 Z 반딧불(#5784) None (JOI12_rotate) C++17
0 / 100
115 ms 65540 KB
#include <bits/stdc++.h>

using namespace std;

struct Matrix{
    char c;
    Matrix *r = nullptr, *d = nullptr;
    Matrix(){}
    Matrix(char c): c(c){}
    ~Matrix(){
        if(d) delete d;
    }
};

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

Matrix *MA[4][1005];
void makeMatrix(){
    vector<Matrix*> v[4];
    for(int i=0; i<4; i++) v[i] = vector<Matrix*> (MA[i], MA[i]+n+2);

    for(int i=1; i<=n+1; i++){
        for(int j=0; j<=n+1; j++){
            v[0][j]->d = new Matrix(j ? arr[i][j] : ' ');
            v[1][j]->d = new Matrix(j ? arr[n+1-j][i] : ' ');
            v[2][j]->d = new Matrix(j ? arr[n+1-i][n+1-j] : ' ');
            v[3][j]->d = new Matrix(j ? arr[j][n+1-i] : ' ');
            for(int k=0; k<4; k++){
                v[k][j] = v[k][j]->d;
//                v[k][j]->dir = k, v[k][j]->i = i, v[k][j]->j = j;
            }
        }
        for(int k=0; k<4; k++) for(int j=0; j<n; j++) v[k][j]->r = v[k][j+1];
    }
}

void rotateMatrix(int x, int y, int d){
    vector<Matrix*> 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] = corner[0]->d;
    for(int z=0; z<y-1; z++) corner[1] = corner[1]->d;
    for(int z=0; z<n+1-(x+d); z++) corner[2] = corner[2]->d;
    for(int z=0; z<n+1-(y+d); z++) corner[3] = corner[3]->d;

    vector<Matrix*> corner2 = corner;
    vector<Matrix*> corner3;

    for(int i=1; i<=d; i++){
        vector<Matrix*> tmp;
        for(int k=0; k<4; k++) corner2[k] = corner2[k]->r;
        tmp = vector<Matrix*> {corner2[3]->d, corner2[0]->d, corner2[1]->d, corner2[2]->d};
        for(int k=0; k<4; k++) corner2[k]->d = tmp[k];
    }
    corner3 = corner2;
    for(int k=0; k<4; k++) corner2[k] = corner2[k]->r;
    for(int i=1; i<=d; i++){
        for(int k=0; k<4; k++) corner2[k] = corner2[k]->d, corner3[k] = corner3[k]->d;
        for(int k=0; k<4; k++) corner3[k]->r = corner2[k];
    }

    corner2 = corner;
    for(int i=1; i<=d; i++){
        vector<Matrix*> tmp;
        for(int k=0; k<4; k++) corner2[k] = corner2[k]->d;
        tmp = vector<Matrix*> {corner2[3]->r, corner2[0]->r, corner2[1]->r, corner2[2]->r};
        for(int k=0; k<4; k++) corner2[k]->r = tmp[k];
    }
    corner3 = corner2;
    for(int k=0; k<4; k++) corner2[k] = corner2[k]->d;
    for(int i=1; i<=d; i++){
        for(int k=0; k<4; k++) corner2[k] = corner2[k]->r, corner3[k] = corner3[k]->r;
        for(int k=0; k<4; k++) 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 i=0; i<=n+1; i++){
        for(int j=0; j<4; j++){
            MA[j][i] = new Matrix(' ');
//            MA[j][i]->dir = j, MA[j][i]->i = 0, MA[j][i]->j = i;
        }
        if(i) for(int j=0; j<4; j++) MA[j][i-1]->r = MA[j][i];
    }
    makeMatrix();

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

    for(int j=1; j<=n; j++){
        Matrix* tmp = MA[0][j];
        for(int i=1; i<=n; i++){
            tmp = tmp->d;
            arr[i][j] = tmp->c;
        }
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            printf("%c", arr[i][j]);
        }
        puts("");
    }

    for(int k=0; k<4; k++) for(int i=0; i<=n+1; i++) delete MA[k][i];
}

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:94:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   94 |         scanf("%d %d %d", &x, &y, &d);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 3328 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 108 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 107 ms 65540 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 108 ms 65540 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 111 ms 65540 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 110 ms 65536 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 115 ms 65540 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 110 ms 65540 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 108 ms 65540 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 111 ms 65540 KB Execution killed with signal 9