QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#203565#7535. Limited Shuffle Restoring275307894aWA 1ms4000kbC++141.3kb2023-10-06 18:13:432023-10-06 18:13:43

Judging History

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

  • [2023-10-06 18:13:43]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4000kb
  • [2023-10-06 18:13:43]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=1e4+1,M=100+1,K=600+5,mod=1e9+7,Mod=mod-1;const db eps=1e-6;const ll INF=1e18+7;mt19937 rnd(263082);
int n;
map<pii,int> f;
int ask(int x,int y){
	auto it=f.find(make_pair(x,y));if(it!=f.end()) return it->se;
	char c;cout<<"? "<<x<<' '<<y<<endl;
	cin>>c;return f[make_pair(x,y)]=(c=='<');
}
int A[N];
void Solve(){
	cin>>n;
	if(n==1){cout<<"! 1"<<endl;return;}
	int i1=n-1,i2=n;
	for(int i=n;i>2;i--){
		int p=i-2;
		int o1=ask(p,i1),o2=ask(p,i2),o3=ask(i1,i2);
		if(!o1&&!o2){
			A[p]=i;
			if(i>3&&!o3) A[i1]=i-1,i1=i-3,i--;
		} 
		else if(o3&&o2) A[i2]=i,i2=i1,i1=p;
		else A[i1]=i,i1=p;
	}
	if(ask(i1,i2)) A[i1]=1,A[i2]=2;
	else A[i1]=2,A[i2]=1;
	cout<<"! ";for(int i=1;i<=n;i++) cout<<A[i]<<' ';cout<<endl;
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3984kb

input:

5
<
<
>
>
<
<
>

output:

? 3 4
? 3 5
? 4 5
? 2 3
? 2 5
? 1 2
? 1 3
! 2 3 1 5 4 

result:

ok yeah, seems ok, spent 7 queries of 13

Test #2:

score: 0
Accepted
time: 0ms
memory: 4000kb

input:

1

output:

! 1

result:

ok yeah, seems ok, spent 0 queries of 6

Test #3:

score: 0
Accepted
time: 1ms
memory: 3976kb

input:

2
>

output:

? 1 2
! 2 1 

result:

ok yeah, seems ok, spent 1 queries of 8

Test #4:

score: 0
Accepted
time: 0ms
memory: 3980kb

input:

3
>
>
>

output:

? 1 2
? 1 3
? 2 3
! 3 2 1 

result:

ok yeah, seems ok, spent 3 queries of 10

Test #5:

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

input:

4
>
>
>
>

output:

? 2 3
? 2 4
? 3 4
? 1 4
! 2 4 3 1 

result:

wrong answer this is not the only answer, for example, we could have guessed [3, 4, 2, 1]