QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#344507 | #8216. Jumbled Primes | Crysfly# | RE | 0ms | 0kb | C++17 | 3.4kb | 2024-03-04 18:04:04 | 2024-03-04 18:04:05 |
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=100;
//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=1000;
while(T--)work();
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
16 3 1 1 1 3 2 2 1 1 1 2 6 3 2 1 12 4 4 32 12 3 1 3 2 24 3 1 1 1 3 1 3 1 8 3 2 24 2 1 1 1 4 32 2 1 6 6 4 1 1 1 6 3 1 3 2 2 4 1 4 3 1 48 12 4 3 1 3 2 8 2 2 16 8 1 2 1 1 1 6 3 1 6 4 3 2 6 8 3 1 6 2 1 4 1 1 12 2 3 7 1 1 3 2 2 1 1 1 2 4 6 3 14 1 12 4 4 4 12 3 1 3 2 12 3 1 1 1 3 1 3 1 4 21 2 12 2 1 1 1 4...
output:
? 83 12 ? 83 1 ? 83 2 ? 83 3 ? 83 4 ? 83 5 ? 83 6 ? 83 7 ? 83 8 ? 83 9 ? 83 10 ? 83 11 ? 83 13 ? 83 14 ? 83 15 ? 83 16 ? 83 17 ? 83 18 ? 83 19 ? 83 20 ? 83 21 ? 83 22 ? 83 23 ? 83 24 ? 83 25 ? 83 26 ? 83 27 ? 83 28 ? 83 29 ? 83 30 ? 83 31 ? 83 32 ? 83 33 ? 83 34 ? 83 35 ? 83 36 ? 83 37 ? 83 38 ? 83 ...