QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#672150#7757. Palm IslandkkkkkWA 1ms7924kbC++201.4kb2024-10-24 15:51:382024-10-24 15:51:39

Judging History

你现在查看的是最新测评结果

  • [2024-10-24 15:51:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7924kb
  • [2024-10-24 15:51:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
typedef pair<PII,ll> PIII;
#define endl '\n'
#define x first
#define y second
const ll N =2e5+100,M=30,INF = 1e18;
ll n,a[N],b[N],l[N],r[N];
deque<ll> q;
bool check(){
	deque<ll> pp=q;
	ll idx=1;
	while(!pp.empty()){
		ll x=pp.front();
		pp.pop_front();
		if(x==idx) idx++;
		else return false;
	}
	return true;
}
void solve(){
	cin>>n;
	vector<ll> ans;
	map<ll,ll> pos;
	for(ll i=1;i<=n;i++){
		if(i==1) l[i]=n;
		else l[i]=i-1;
		if(i==n) r[i]=1;
		else r[i]=i+1;
		cin>>a[i];
		pos[a[i]]=i;
	}
	for(ll i=1;i<=n;i++) cin>>b[i];
	for(ll i=1;i<=n;i++){
		if(b[i]!=i){
			a[pos[b[i]]]=i;
			b[i]=i;
		}
	}
	q.clear();
	for(ll i=1;i<=n;i++) q.push_back(a[i]);
	if(check()){
		cout<<endl;
		return ;
	}
	for(ll i=1;i<=n;i++){
		ll x=q.front();
		q.pop_front();
		ll y=q.front();
		while(r[x]!=y){
			q.pop_front();
			q.push_back(y);
			ans.push_back(2);
			y=q.front();
		}
		q.push_front(x);
		ll pp=l[x];
		while(x!=pp){
			q.pop_front();
			q.push_back(x);
			ans.push_back(1);
			x=q.front();
		}
	}
	while(q.front()!=1){
		ll x=q.front();
		q.pop_front();
		q.push_back(x);
		ans.push_back(1);
	}
	for(auto j:ans) cout<<j;
	cout<<endl;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	ll __=1;cin>>__;
    while(__--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7644kb

input:

2
3
1 2 3
2 3 1
4
1 2 3 4
2 1 3 4

output:

1111111
2111111111111111

result:

ok Correct. (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 7924kb

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:

11111111
2112111111111
22111111111111111
222111211111111111111111111
22111111121111111111111111
11111111111111
11111111
112111111111111
22111111111111
11111111
21111111
22111111111111111
2111111
211111111
11111111111111111111111
112111111111111
221121111111111
1111111

21112111111111111111111
112111...

result:

wrong answer On Case#3: The lenght of your output is 17(exceed n*n = 16). (test case 3)