QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#344499 | #8216. Jumbled Primes | Crysfly# | TL | 0ms | 0kb | C++17 | 3.4kb | 2024-03-04 17:59:29 | 2024-03-04 17:59:31 |
answer
// what is matter? never mind.
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 105
#define inf 0x3f3f3f3f
int n;
mt19937_64 rnd(time(0));
int per[maxn];
int mp[maxn][maxn],cnt;
int Q(int a,int b){
assert(a!=b);
if(mp[a][b]!=-1)return mp[a][b];
++cnt;
if(cnt>600*1000)exit(23);
//return __gcd(per[a],per[b]);
cout<<"? "<<a<<" "<<b<<endl;
assert(cin>>mp[a][b]);
mp[b][a]=mp[a][b]; return mp[a][b];
}
int p[7]={1,2,3,5,7};
int id[7];
int up[maxn];
int ask(int a,int b){
int x=Q(a,b);
up[a]=up[a]*x/__gcd(x,up[a]);
up[b]=up[b]*x/__gcd(x,up[b]);
return x;
}
vi buc[7];
bool res[maxn];
vi o1={0, 4, 9, 25,49};
vi oo={0,2*21,3*10,15,14};
int id2[6];
void find2(){
For(i,1,4){
id2[i]=0;
For(j,1,n) if(up[j]%o1[i]==0) id2[i]=j;
// cerr<<"id2 "<<o1[i]<<" "<<id2[i]<<" "<<per[id2[i]]<<"\n";
}
}
void work()
{
n=read();
//cnt=0;
For(i,1,n)For(j,1,n)mp[i][j]=-1;
For(i,1,n)up[i]=1,res[i]=0;
For(i,0,4)buc[i].clear();
For(i,1,n)per[i]=i; shuffle(per+1,per+n+1,rnd);
For(i,1,4){
id[i]=0;
For(j,1,n)if(up[j]%p[i]==0)id[i]=j;
if(!id[i]){
while(!id[i]){
int u=rnd()%n+1;
int v=rnd()%n+1;
while(v==u)v=rnd()%n+1;
ask(u,v);
if(up[u]%p[i]==0)id[i]=u;
}
}
For(j,1,n)if(j!=id[i]){
ask(id[i],j);
}
For(j,1,n)if(up[j]==p[i])buc[i].pb(j);
shuffle(ALL(buc[i]),rnd);
}
For(i,1,n) if(up[i]==1) res[i]=1;
// cerr<<"cnt "<<cnt<<"\n";
find2();
Rep(i,4,1){
// cout<<"sz "<<buc[i].size()<<"\n";
for(int x:buc[i]){
bool is=1;
if(up[x]!=p[i]) is=0;
vi o;
For(j,1,n)
if(__gcd(up[j],2*3*5*7ll*2*3*5*7ll)==p[i-1])o.pb(j);
shuffle(ALL(o),rnd);
if(is){
for(int y:o){
ask(x,y);
if(up[x]!=p[i]){
is=0;
break;
}
}
}
if(is){
if(id2[i]){
if(x!=id2[i]) ask(x,id2[i]);
else is=0;
}else{
// cout<<"qwq "<<i<<"\n";
// cout<<"x: "<<per[x]<<"\n";
find2();
For(j,1,n){
// cout<<"j: "<<j<<" "<<per[j]<<" "<<up[j]<<" "<<__gcd(up[j],oo[i])<<"\n";
if(__gcd(up[j],oo[i])==oo[i] && j!=x){
// cout<<"Ask "<<per[j]<<"\n";
ask(x,j);
if(up[x]!=p[i]){
is=0;
break;
}
if(up[j]%o1[i]==0){
break;
}
}
}
}
if(up[x]!=p[i]) is=0;
}
if(is){
res[x]=1;
// cout<<"find: "<<x<<" "<<per[x]<<"\n";
// assert(per[x]==p[i]);
// for(int y:o) cout<<"y: "<<per[y]<<"\n";
break;
}
}
}
// cerr<<"cnts "<<cnt<<"\n";
cout<<"! ";For(i,1,n)cout<<res[i];cout<<endl;
}
signed main()
{
int T=1; cin>>T;
while(T--)work();
return 0;
}
/*
*/
詳細信息
Test #1:
score: 0
Time Limit Exceeded