QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#373578#5207. Interactive Factorial GuessingInfinityNS#TL 900ms471120kbC++141016b2024-04-01 20:27:272024-04-01 20:27:28

Judging History

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

  • [2024-04-01 20:27:28]
  • 评测
  • 测评结果:TL
  • 用时:900ms
  • 内存:471120kb
  • [2024-04-01 20:27:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define pb push_back

const int lim=5982;
const int N=20000;
int fac[lim+1][N];
int main(){
	fac[1][0]=1;
	for(int i=2;i<=lim;i++){
		int carry=0;
		for(int j=0;j<N;j++){
			carry+=i*fac[i-1][j];
			fac[i][j]=carry%10;
			carry/=10;
		}
	}
	int t;
	scanf("%i",&t);
	while(t--){
		vector<int> cand;
		for(int i=1;i<=lim;i++)cand.pb(i);
		while(cand.size()>1){
			int best=-1,now=cand.size()+1;
			for(int j=0;j<N;j++){
				vector<int> cnt(10,0);
				for(int i:cand){
					cnt[fac[i][j]]++;
				}
				int mx=0;
				for(int i=0;i<10;i++){
					mx=max(mx,cnt[i]);
				}
				if(mx<now){
					now=mx;
					best=j;
				}
			}
			printf("? %i\n",best);
			fflush(stdout);
			int cif;
			scanf("%i",&cif);
			vector<int> newCand;
			for(int i:cand){
				if(fac[i][best]==cif){
					newCand.pb(i);
				}
			}
			cand=newCand;
		}
		printf("! %i\n",cand[0]);
		fflush(stdout);
		char s[10];
		scanf("%s",s);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 900ms
memory: 471120kb

input:

2
0
0
0
0
0
0
0
0
0
1
YES
2
8
0
0
YES

output:

? 1601
? 181
? 2001
? 28
? 226
? 1487
? 6
? 1
? 24
? 0
! 1
? 1601
? 1692
? 1429
? 1465
! 5982

result:

ok single line: 'OK'

Test #2:

score: -100
Time Limit Exceeded

input:

100
0
0
0
0
0
4
7
YES
1
5
2
3
YES
7
5
0
5
YES
1
4
3
4
YES
0
0
2
6
3
YES
4
9
5
7
YES
7
8
5
5
YES
8
5
3
4
YES
6
2
1
0
YES
7
6
6
1
YES
5
7
7
9
YES
7
9
6
0
YES
7
5
4
1
YES
8
2
3
9
YES
0
0
5
9
0
YES
8
8
2
7
YES
3
8
9
4
YES
6
6
4
2
YES
9
9
3
1
YES
9
8
4
9
YES
0
0
9
0
0
YES
8
0
5
0
YES
2
7
6
8
YES
6
1
4
2
...

output:

? 1601
? 181
? 2001
? 28
? 226
? 1487
? 1355
! 4593
? 1601
? 1483
? 1666
? 1171
! 4688
? 1601
? 1786
? 1393
? 1480
! 5747
? 1601
? 1483
? 1376
? 1006
! 3416
? 1601
? 181
? 2001
? 1461
? 1345
! 3862
? 1601
? 1543
? 1383
? 1214
! 3367
? 1601
? 1786
? 2180
? 1175
! 2721
? 1601
? 1456
? 2608
? 1344
! 38...

result: