QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#595136 | #7757. Palm Island | forget-star# | WA | 1ms | 7652kb | C++14 | 1.3kb | 2024-09-28 12:41:11 | 2024-09-28 12:41:23 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define ll long long
using namespace std;
const int N=1e6+7,inf = 2e9+77777777;
int read()
{
int a = 0,x = 1;char ch = getchar();
while(ch > '9' || ch < '0') {if(ch == '-') x = -1;ch = getchar();}
while(ch >= '0' && ch <= '9') {a = a*10 + ch-'0';ch = getchar();}
return a*x;
}
int n,b[N],p[N],o,ans[N];
struct node{
int l,r,num;
}a[N];
int nxt() {return a[a[o].r].num;}
void op1() {o = a[o].r;}
void op2()
{
int xt1 = a[o].r;
swap(a[o].num,a[xt1].num);
op1();
}
void solve()
{
n = read();o = 0;int cnt= 0;
for(int i = 0;i < n;i ++) a[i].num = read(),a[i].l = (i+n-1)%n,a[i].r = (i+1)%n;
for(int i = 0;i < n;i ++) b[i] = read();
for(int i = 0;i < n;i ++) p[b[i]] = b[(i+1)%n];
for(int i = 1;i < n;i ++) {
if(nxt() != p[a[o].num]) {
ans[++cnt] = 2;
op2();
} else {
ans[++cnt] = 1;
op1();
}
}
while(a[o].num != b[0]) {
ans[++cnt] = 1;
op1();
}
for(int i= 1;i <= cnt;i ++) printf("%d",ans[i]);
puts("");
}
int main()
{
// freopen("in.in","r",stdin);freopen("out.out","w",stdout);
int T = read();
while(T --) solve();
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7652kb
input:
2 3 1 2 3 2 3 1 4 1 2 3 4 2 1 3 4
output:
1111 2111
result:
ok Correct. (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 7644kb
input:
200 3 3 1 2 2 3 1 4 2 4 1 3 2 1 4 3 4 1 4 2 3 2 1 3 4 5 4 3 2 1 5 2 4 5 3 1 5 2 1 5 4 3 5 2 4 1 3 4 4 3 1 2 1 2 4 3 3 1 2 3 3 1 2 4 1 4 2 3 2 1 4 3 4 1 3 2 4 1 4 3 2 3 3 2 1 1 3 2 3 2 3 1 1 3 2 4 1 4 3 2 3 1 2 4 3 1 2 3 1 3 2 3 3 2 1 2 3 1 5 5 1 3 2 4 2 4 5 1 3 4 4 3 1 2 1 4 3 2 4 1 3 4 2 2 4 3 1 3 ...
output:
11 21211 22111 222111 221211 111111 11 12111 221111 11 21 22111 2111 211 11111111 12111 221 1111 1111 2112 121 22111 211 121111 2221111 1111 212111 122111 121 211111 2111 221 211 221111 2211 222111 211 22111 2211 111 221 11 2111111 12111 221111 22211111 2111 11 22111111 111 1211 1121111 211 22111 22...
result:
wrong answer On Case#2: After your operations, a[2] = 3 but a[2] = 1. (test case 2)