QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#869616 | #2735. Shifty Grid | hhoppitree | 0 | 41ms | 4352kb | C++17 | 2.1kb | 2025-01-25 12:06:11 | 2025-01-25 12:06:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, m, a[N][N], b[N];
vector< array<int, 3> > res;
void opt(int dir, int x, int y) {
if (dir == 1) {
y = (y % m + m) % m;
res.push_back({dir, x, y});
for (int i = 0; i < m; ++i) b[(i + y) % m] = a[x][i];
for (int i = 0; i < m; ++i) a[x][i] = b[i];
} else {
y = (y % n + n) % n;
res.push_back({dir, x, y});
for (int i = 0; i < n; ++i) b[(i + y) % n] = a[i][x];
for (int i = 0; i < n; ++i) a[i][x] = b[i];
}
}
signed main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) scanf("%d", &a[i][j]);
}
for (int i = 0; i + 1 < n; ++i) {
for (int j = 0; j < m; ++j) {
if (a[i][j] == i * m + j) continue;
for (int k = j + 1; k < m; ++k) {
if (a[i][k] == i * m + j) opt(2, k, 1), opt(1, i + 1, (k == j + 1 ? 1 : -1)), opt(2, k, -1);
}
for (int k = i + 1; k < n; ++k) {
if (a[k][j] == i * m + j) opt(1, k, 1);
}
for (int k = i + 1; k < n; ++k) {
for (int l = 0; l < m; ++l) {
if (a[k][l] != i * m + j) continue;
opt(2, j, k - i), opt(1, k, j - l), opt(2, j, i - k);
break;
}
}
}
}
int D = 1;
for (int i = 0; i < m; ++i) {
if (a[n - 1][i] == (n - 1) * m + i) continue;
for (int j = i + 1; j < m; ++j) {
if (a[n - 1][j] != (n - 1) * m + i) continue;
opt(1, n - 1, m - 1 - j), opt(2, m - 1, D), opt(1, n - 1, j - i), opt(2, m - 1, -D);
opt(1, n - 1, m - (j - i)), opt(2, m - 1, D), opt(1, n - 1, j + 1);
D = -D;
break;
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) cerr << a[i][j] << " \n"[j == m - 1];
}
printf("%d\n", (int)res.size());
for (auto [x, y, z] : res) printf("%d %d %d\n", x, y + 1, z);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 0ms
memory: 3840kb
input:
2 2 0 1 2 3
output:
0
result:
ok
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 3840kb
input:
4 2 5 2 1 3 6 4 0 7
output:
24 1 4 1 2 1 3 1 4 1 2 1 1 2 2 1 1 2 1 2 2 3 2 2 1 1 4 1 2 2 3 1 4 1 2 1 1 1 4 1 2 1 3 2 2 1 1 4 1 2 2 3 1 4 0 2 2 1 1 4 1 2 2 3 1 4 1 2 2 1 1 4 0
result:
wrong answer
Subtask #2:
score: 0
Wrong Answer
Test #11:
score: 10
Accepted
time: 5ms
memory: 3840kb
input:
100 100 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 10...
output:
0
result:
ok
Test #12:
score: 10
Accepted
time: 2ms
memory: 3840kb
input:
100 100 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 199 1...
output:
984 1 100 1 2 100 99 1 100 99 2 100 1 2 100 98 1 100 1 2 100 2 2 100 97 1 100 99 2 100 3 2 100 96 1 100 1 2 100 4 2 100 95 1 100 99 2 100 5 2 100 94 1 100 1 2 100 6 2 100 93 1 100 99 2 100 7 2 100 92 1 100 1 2 100 8 2 100 91 1 100 99 2 100 9 2 100 90 1 100 1 2 100 10 2 100 89 1 100 99 2 100 11 2 100...
result:
ok
Test #13:
score: 0
Wrong Answer
time: 41ms
memory: 4352kb
input:
100 100 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 9640 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...
output:
43191 1 5 1 2 41 4 1 5 99 2 41 96 1 6 1 2 41 4 1 6 99 2 41 96 1 7 1 2 41 4 1 7 99 2 41 96 1 8 1 2 41 4 1 8 99 2 41 96 2 41 1 1 6 1 2 41 99 2 40 1 1 6 98 2 40 99 1 9 1 2 41 4 1 9 99 2 41 96 2 100 1 1 7 99 2 100 99 2 1 1 1 7 2 2 1 99 2 2 1 1 7 99 2 2 99 2 3 1 1 7 2 2 3 99 2 4 1 1 7 99 2 4 99 2 5 1 1 7...
result:
wrong answer
Subtask #3:
score: 0
Skipped
Dependency #1:
0%