ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#459 | #91. 「NOIP2020」移球游戏 | Pigsyy | 0 | 0ms | 0kb | C++23 | 4.2kb | 2025-04-24 13:59:08 | 2025-04-24 14:06:16 |
answer
#include <bits/stdc++.h>
#define gc()(xS==xTT&&(xTT=(xS=xB)+fread(xB,1,1<<20,stdin),xS==xTT)?0:*xS++)
#define pc(x) (p3-obuf<1000000)?(*p3++=x):(fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=x)
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;
char xch, xB[1 << 20], *xS = xB, *xTT = xB, obuf[1000000], *p3 = obuf;
inline ll read() {
char ch = gc();
ll x = 0, f = 1;
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = gc();
}
while ('0' <= ch && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = gc();
}
return x * f;
}
static char cc[20];
template<typename item>inline void pt(register item x) {
register int len = 0;
if (!x)
pc('0');
if (x < 0)
x = -x, pc('-');
while (x)
cc[len++] = x % 10 + '0', x /= 10;
while (len--)
pc(cc[len]);
}
inline void pS(string s) {
for (int i = 0; i < s.length(); i++)
pc(s[i]);
}
inline ll read2() {
char ch = gc();
ll x = 0, f = 1;
while (ch < '0' || ch > '1') {
if (ch == '-')
f = -1;
ch = gc();
}
while ('0' <= ch && ch <= '9') {
x = (x << 1) + (ch ^ 48);
ch = gc();
}
return x * f;
}
const int maxn = 55, maxm = 410, maxc = 1e6;
int n, m, a[maxn][maxm], p[maxn], top[maxn], cz[maxc][2], cnt;
void ac(int x, int y) {
cz[++cnt][0] = x, cz[cnt][1] = y;
top[y]++, a[y][top[y]] = a[x][top[x]], top[x]--;
}
int main() {
n = read(), m = read();
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
top[i]++, a[i][j] = read();
for (int i = 1; i <= n + 1; i++)
p[i] = i;
while (n >= 3) {
int tot = 0;
for (int i = 1; i <= m; i++)
if (a[p[1]][i] == n)
tot++;
for (int i = 1; i <= tot; i++)
ac(p[n], p[n + 1]);
for (int i = m; i; i--)
if (a[p[1]][i] == n)
ac(p[1], p[n]);
else
ac(p[1], p[n + 1]);
while (top[p[n + 1]] && a[p[n + 1]][top[p[n + 1]]] != n)
ac(p[n + 1], p[1]);
for (int i = m; i; i--)
if (a[p[2]][i] != n && top[p[1]] < m)
ac(p[2], p[1]);
else
ac(p[2], p[n + 1]);
swap(p[2], p[n + 1]), swap(p[1], p[n]);
for (int t = 1; t < n; t++) {
tot = 0;
for (int i = 1; i <= m; i++)
if (a[p[t]][i] == n)
tot++;
for (int i = 1; i <= tot; i++)
ac(p[n], p[n + 1]);
for (int i = m; i; i--)
if (a[p[t]][i] == n)
ac(p[t], p[n]);
else
ac(p[t], p[n + 1]);
swap(p[n], p[n + 1]), swap(p[n + 1], p[t]);
}
for (int i = 1; i < n; i++) {
while (top[p[i]] && a[p[i]][top[p[i]]] == n)
ac(p[i], p[n + 1]);
while (top[p[i]] < m)
ac(p[n], p[i]);
}
n--;
}
for (int _ = 1; _ <= 2; _++) {
int tot = 0;
for (int i = 1; i <= m; i++)
if (a[p[1]][i] == 1)
tot++;
for (int i = 1; i <= tot; i++)
ac(p[2], p[3]);
for (int i = m; i; i--)
if (a[p[1]][i] == 1)
ac(p[1], p[2]);
else
ac(p[1], p[3]);
for (int i = 1; i <= m - tot; i++)
ac(p[3], p[1]);
for (int i = 1; i <= tot; i++)
ac(p[2], p[1]);
for (int i = 1; i <= tot; i++)
ac(p[3], p[2]);
swap(p[1], p[2]);
}
for (int i = m; i && a[p[1]][i] == 1; i--)
ac(p[1], p[3]);
for (int i = m; i && a[p[2]][i] == 1; i--)
ac(p[2], p[3]);
while (top[p[1]])
ac(p[1], p[2]);
pt(cnt);
for (int i = 1; i <= cnt; i++)
pc('\n'), pt(cz[i][0]), pc(' '), pt(cz[i][1]);
fwrite(obuf, p3 - obuf, 1, stdout);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 0
Checker Judgement Failed
input:
2 20 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1
output:
159 2 3 1 2 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 3 1 3 1 3 1 ...
result:
Test #2:
score: 0
Checker Judgement Failed
input:
2 20 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 2 1
output:
157 2 3 2 3 2 3 1 3 1 2 1 2 1 2 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 3 1 ...
result:
Test #3:
score: 0
Checker Judgement Failed
input:
10 20 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 4 7 2 9 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 10 3 4 1...
output:
2051 10 11 10 11 10 11 10 11 10 11 10 11 10 11 10 11 10 11 10 11 10 11 10 11 10 11 10 11 10 11 10 11...
result:
Test #4:
score: 0
Checker Judgement Failed
input:
10 20 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 1 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 2 3 2 9 3 3 3 3 3 3 3 ...
output:
2025 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 ...
result:
Test #5:
score: 0
Checker Judgement Failed
input:
10 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 6 1 6 8 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 9 2 1 10 3 2 2 2 2 2 2 2...
output:
1991 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 ...
result:
Test #6:
score: 0
Checker Judgement Failed
input:
50 85 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 32 21 34 48 29 15 10 26 23 10 30 39 29 11 37 10 2...
output:
129320 50 51 50 51 1 51 1 51 1 50 1 51 1 51 1 51 1 51 1 51 1 51 1 50 1 51 1 51 1 51 1 51 1 51 1 51 1...
result:
Test #7:
score: 0
Checker Judgement Failed
input:
50 85 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 1...
output:
129303 50 51 1 51 1 50 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 ...
result:
Test #8:
score: 0
Checker Judgement Failed
input:
50 85 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 28 46 38 39 49 21 39 7 17 18 34 2 34 39 3 44 42 2...
output:
129357 50 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 50 1 51 1 51 1 51 1 ...
result:
Test #9:
score: 0
Checker Judgement Failed
input:
50 300 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 2 35 41 4 35 30 2 10 16 36 2 34 10 36 32 18 11 2...
output:
456146 50 51 50 51 50 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 ...
result:
Test #10:
score: 0
Checker Judgement Failed
input:
50 300 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 26 48 48 49 45 48 4 10 27 19 50 30 24 16 9 41 14 19 19 41 15 7 ...
output:
456165 50 51 50 51 50 51 50 51 50 51 50 51 50 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1...
result:
Test #11:
score: 0
Checker Judgement Failed
input:
50 300 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 37 15 25 13 21 35 45 26 26 48 20 38 13 35 15 33 8 16 16 33 1 27...
output:
456212 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 5...
result:
Test #12:
score: 0
Checker Judgement Failed
input:
50 300 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 44 16 43 44 28 25 21 33 12 1 26 22 25 16 4 47 20...
output:
456245 50 51 50 51 50 51 50 51 50 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 5...
result:
Test #13:
score: 0
Checker Judgement Failed
input:
50 300 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 39 15 50 10 9 11 33 24 7 29 31 32 24 50 19 25 18 4 19 40 38 9 6...
output:
456253 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 ...
result:
Test #14:
score: 0
Checker Judgement Failed
input:
50 300 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 26 26 32 15 40 24 49 16 2 35 20 19 23 12 50 44 2...
output:
456232 50 51 50 51 50 51 50 51 50 51 50 51 50 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1...
result:
Test #15:
score: 0
Checker Judgement Failed
input:
50 400 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 ...
output:
608192 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 5...
result:
Test #16:
score: 0
Checker Judgement Failed
input:
50 400 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 42 1 23 50 36 5 41 5 36 17 14 41 47 19 8 20 21 2...
output:
608230 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 1 51 1 51 1 51 1 51 1 51 1 51 1 5...
result:
Test #17:
score: 0
Checker Judgement Failed
input:
50 400 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 25 27 49 4 5 27 9 42 20 43 37 12 22 1 17 34 8 29 6 39 30 30 49 ...
output:
608344 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 1 51 1 51 1 51 1 51 1 51 1 ...
result:
Test #18:
score: 0
Checker Judgement Failed
input:
50 400 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 47 5 39 47 4 16 43 19 34 45 25 26 50 1 25 41 46 ...
output:
608227 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 1 51 1 51 1 51 1 51 1...
result:
Test #19:
score: 0
Checker Judgement Failed
input:
50 400 50 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 ...
output:
608431 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 51 50 ...
result:
Test #20:
score: 0
Checker Judgement Failed
input:
50 400 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 ...
output:
609328 50 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 51 1 ...