Submission #803484

# Submission time Handle Problem Language Result Execution time Memory
803484 2023-08-03T04:36:29 Z 반딧불(#10100) Shifty Grid (CCO17_shifty) C++17
0 / 25
0 ms 212 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, m;
int arr[102][102];
int idxX[10002], idxY[10002];

struct dat{
    int a, b, c;
    dat(){}
    dat(int a, int b, int c): a(a), b(b), c(c){}
};
vector<dat> ans;

int tmp[102];

void rotateRow(int i, int c){
    for(int j=0; j<m; j++) tmp[j] = arr[i][j];
    for(int j=0; j<m; j++){
        arr[i][j] = tmp[(j+m-c)%m];
        idxX[arr[i][j]] = i, idxY[arr[i][j]] = j;
    }
    ans.push_back(dat(1, i, c));
}

void rotateColumn(int j, int c){
    for(int i=0; i<n; i++) tmp[i] = arr[i][j];
    for(int i=0; i<n; i++){
        arr[i][j] = tmp[(i+n-c)%n];
        idxX[arr[i][j]] = i, idxY[arr[i][j]] = j;
    }
    ans.push_back(dat(2, j, c));
}

void sendU(int sx, int sy, int ex, int ey){
    if(sx==ex && sy==ey) return;
    if(sx != ex && sy != ey){
        rotateColumn(ey, (sx-ex+n)%n);
        rotateRow(sx, (ey-sy+m)%m);
        rotateColumn(ey, (ex-sx+n)%n);
        rotateRow(sx, (sy-ey+m)%m);
    }
    else if(sy == ey){
        rotateRow(sx, 1);
        rotateColumn(ey, (sx-ex+n)%n);
        rotateRow(sx, m-1);
        rotateColumn(ey, (ex-sx+n)%n);
    }
    else{
        rotateColumn(sy, 1);
        rotateRow(ex, (sy-ey+m)%m);
        rotateColumn(sy, n-1);
        rotateRow(ex, (ey-sy+m)%m);
    }
}

void sendL(int sx, int sy, int ex, int ey){
    if(sx==ex && sy==ey) return;
    if(sx != ex && sy != ey){
        rotateRow(ex, (sy-ey+m)%m);
        rotateColumn(sy, (ex-sx+n)%n);
        rotateRow(ex, (ey-sy+m)%m);
        rotateColumn(sy, (sx-ex+n)%n);
    }
    else if(sx == ex){
        rotateColumn(sy, 1);
        rotateRow(ex, (sy-ey+m)%m);
        rotateColumn(sy, n-1);
        rotateRow(ex, (ey-sy+m)%m);
    }
    else{
        rotateRow(sx, 1);
        rotateColumn(ey, (sx-ex+n)%n);
        rotateRow(sx, m-1);
        rotateColumn(ey, (ex-sx+n)%n);
    }
}

int main(){
    scanf("%d %d", &n, &m);
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            scanf("%d", &arr[i][j]);
            idxX[arr[i][j]] = i, idxY[arr[i][j]] = j;
        }
    }

    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            sendU(idxX[i*m+j], idxY[i*m+j], i, j);
        }
    }

//    for(int i=0; i<n; i++){
//        for(int j=0; j<m; j++){
//            printf("%2d ", arr[i][j]);
//        }
//        puts("");
//    }

    printf("%d\n", (int)ans.size());
    for(dat p: ans) printf("%d %d %d\n", p.a, p.b, p.c);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:83:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:86:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |             scanf("%d", &arr[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Integer parameter [name=i] equals to 0, violates the range [1, 2]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Integer parameter [name=i] equals to 0, violates the range [1, 2]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Integer parameter [name=i] equals to 0, violates the range [1, 2]
2 Halted 0 ms 0 KB -