답안 #288932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
288932 2020-09-02T07:57:00 Z 반딧불(#5784) 회전 (JOI12_rotate) C++17
0 / 100
128 ms 65540 KB
#include <bits/stdc++.h>

using namespace std;

struct Matrix{
    int i=0, j=0, dir=0; 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+1);

    for(int i=1; i<=n; i++){
        for(int j=0; j<=n; 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];
    }
}

Matrix *moveTo(Matrix *m, int step){
    while(step--) m = m->d;
    return m;
}

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

    for(int i=0; i<=n; 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;
        }
    }
    n--;
    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; i++) delete MA[k][i];
}

Compilation message

rotate.cpp: In function 'int main()':
rotate.cpp:80:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   80 |     scanf("%d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
rotate.cpp:82:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   82 |         scanf("%s", arr[i]+1);
      |         ~~~~~^~~~~~~~~~~~~~~~
rotate.cpp:97:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   97 |         scanf("%d %d %d", &x, &y, &d);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 4608 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 94 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 95 ms 65540 KB Execution killed with signal 9
# 결과 실행 시간 메모리 Grader output
1 Runtime error 101 ms 65540 KB Execution killed with signal 9
# 결과 실행 시간 메모리 Grader output
1 Runtime error 104 ms 65540 KB Execution killed with signal 9
# 결과 실행 시간 메모리 Grader output
1 Runtime error 95 ms 65540 KB Execution killed with signal 9
# 결과 실행 시간 메모리 Grader output
1 Runtime error 93 ms 65540 KB Execution killed with signal 9
# 결과 실행 시간 메모리 Grader output
1 Runtime error 128 ms 65536 KB Execution killed with signal 9
# 결과 실행 시간 메모리 Grader output
1 Runtime error 94 ms 65540 KB Execution killed with signal 9
# 결과 실행 시간 메모리 Grader output
1 Runtime error 102 ms 65540 KB Execution killed with signal 9