# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
803306 |
2023-08-03T04:06:24 Z |
박영우(#10104) |
Shifty Grid (CCO17_shifty) |
C++17 |
|
88 ms |
2440 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 110
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define MOD 1000000007
vector<pair<int, pii>> ansv;
int mp[MAX][MAX];
int cpy[MAX];
int N, M;
pii find(int x) {
int i, j;
for (i = 0; i < N; i++) for (j = 0; j < M; j++) if (mp[i][j] == x) return pii(i, j);
}
int get(int i, int j) {
return i * M + j;
}
void add(int op, int x, int y) {
if (!y) return;
if (op == 1) y %= M;
else y %= N;
if (y < 0) {
if (op == 1) y += M;
else y += N;
}
ansv.emplace_back(op, pii(x, y));
int i;
if (op == 1) {
for (i = 0; i < M; i++) cpy[i] = mp[x][i];
for (i = 0; i < M; i++) mp[x][i] = cpy[(i - y + M) % M];
}
else {
for (i = 0; i < N; i++) cpy[i] = mp[i][x];
for (i = 0; i < N; i++) mp[i][x] = cpy[(i - y + N) % N];
}
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
cin >> N >> M;
int i, j;
for (i = 0; i < N; i++) for (j = 0; j < M; j++) cin >> mp[i][j];
for (j = 0; j < M; j++) {
for (i = 0; i < N - 1; i++) {
auto [x, y] = find(get(i, j));
if (y == j) {
add(2, j, -x - 1);
add(1, N - 1, 1);
add(2, j, x + 1);
add(1, N - 1, -1);
add(2, j, -1);
}
else {
add(2, y, N - 1 - x);
add(1, N - 1, j - y);
add(2, j, -1);
}
}
}
vector<int> v, rev(M);
for (j = 0; j < M; j++) v.push_back(mp[N - 1][j] - N * M + M), rev[v[j]] = j;
vector<pii> swaps;
for (i = 0; i < M; i++) {
if (v[i] == i) continue;
int k = rev[i];
swaps.emplace_back(i, k);
swap(rev[v[i]], rev[v[k]]);
swap(v[i], v[k]);
}
for (auto& [a, b] : swaps) {
if (a == b) continue;
int t;
for (t = 1; t < N; t++) {
add(2, a, -1);
add(1, N - 1, a - b);
add(2, a, 1);
add(1, N - 1, b - a);
add(2, a, -1);
}
}
cout << ansv.size() << ln;
for (auto& [op, p] : ansv) cout << op << bb << p.first + 1 << bb << p.second << ln;
}
Compilation message
Main.cpp: In function 'pii find(int)':
Main.cpp:20:1: warning: control reaches end of non-void function [-Wreturn-type]
20 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
63 ms |
2336 KB |
Output is correct |
6 |
Correct |
65 ms |
2336 KB |
Output is correct |
7 |
Correct |
69 ms |
2432 KB |
Output is correct |
8 |
Correct |
70 ms |
2352 KB |
Output is correct |
9 |
Correct |
63 ms |
2352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
63 ms |
2336 KB |
Output is correct |
18 |
Correct |
65 ms |
2336 KB |
Output is correct |
19 |
Correct |
69 ms |
2432 KB |
Output is correct |
20 |
Correct |
70 ms |
2352 KB |
Output is correct |
21 |
Correct |
63 ms |
2352 KB |
Output is correct |
22 |
Correct |
64 ms |
2368 KB |
Output is correct |
23 |
Correct |
77 ms |
2328 KB |
Output is correct |
24 |
Correct |
80 ms |
2172 KB |
Output is correct |
25 |
Correct |
63 ms |
2356 KB |
Output is correct |
26 |
Correct |
69 ms |
2440 KB |
Output is correct |
27 |
Correct |
86 ms |
2364 KB |
Output is correct |
28 |
Correct |
83 ms |
2020 KB |
Output is correct |
29 |
Correct |
85 ms |
1996 KB |
Output is correct |
30 |
Correct |
85 ms |
1936 KB |
Output is correct |
31 |
Correct |
83 ms |
2000 KB |
Output is correct |
32 |
Correct |
88 ms |
1984 KB |
Output is correct |
33 |
Correct |
7 ms |
680 KB |
Output is correct |
34 |
Correct |
9 ms |
776 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
48 ms |
1484 KB |
Output is correct |
37 |
Correct |
6 ms |
664 KB |
Output is correct |
38 |
Correct |
7 ms |
664 KB |
Output is correct |
39 |
Correct |
8 ms |
664 KB |
Output is correct |
40 |
Correct |
21 ms |
1028 KB |
Output is correct |
41 |
Correct |
7 ms |
696 KB |
Output is correct |
42 |
Correct |
6 ms |
664 KB |
Output is correct |
43 |
Correct |
40 ms |
1352 KB |
Output is correct |
44 |
Correct |
5 ms |
656 KB |
Output is correct |
45 |
Correct |
26 ms |
1260 KB |
Output is correct |
46 |
Correct |
14 ms |
920 KB |
Output is correct |