QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#793243#8952. 解谜游戏misfits#6 124ms4120kbC++144.6kb2024-11-29 17:55:322024-11-29 17:55:33

Judging History

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

  • [2024-11-29 17:55:33]
  • 评测
  • 测评结果:6
  • 用时:124ms
  • 内存:4120kb
  • [2024-11-29 17:55:32]
  • 提交

answer

#include<bits/stdc++.h>
#include "puzzle.h"
#define LL int
#define SZ(x) ((LL)(x.size()))
#define all(x) (x).begin(),(x).end()
using namespace std;
/*inline LL read(){
  LL q=0,w=1;char ch=getchar();
  while(ch>'9' || ch<'0'){if(ch=='-')w=-1;ch=getchar();}
  while(ch>='0'&&ch<='9'){q=q*10+(ch-'0');ch=getchar();}
  return q*w;
}
void write(LL x){
  if(x<0){putchar('-');x=(-x);}
  if(x>9)write(x/10);
  putchar('0'+x%10);
}
inline void writeln(LL x){write(x);puts("");}
inline void writecs(LL x){write(x);putchar(' ');}*/

inline void dmin(LL &x,LL y){if(x>y)x=y;return ;}
inline void dmax(LL &x,LL y){if(x<y)x=y;return ;}

#define cout cerr
#define pb push_back

namespace GenHelper{
#define ull unsigned long long
  ull seed=19260817ull;
  inline void Get(){seed^=(seed<<7);seed^=(seed>>11);seed^=(seed<<13);}
  inline ull Rand(){Get();return (seed^(seed<<32ull));}
}using GenHelper::Rand;
inline LL random(LL l,LL r){return (Rand()%(r-l+1)+l);}

const LL N = 1000+95 ;
LL n;bitset<N>p,q;LL ans[N],X=-1,Y=-1,TEMP;
//(X,Y) 表示一组已经找到的匹配

inline void link(LL x,LL y){//当前确定了 p[x]=y
  p[x]=0;q[y]=0;ans[x]=y;
  if(X==-1){X=x;Y=y;}
  TEMP++;return ;
}

vector<LL>__GET(vector<LL>&a,vector<LL>&b){
  vector<LL>p(n);
  for(LL i=0;i<n;i++)p[i]=ans[i];
  for(LL i=0;i<SZ(a);i++)p[a[i]]=b[i];
  for(LL i=0;i<n;i++)assert(p[i]!=-1);
  return p;
}

inline LL GET(vector<LL>&a,vector<LL>&b){
  vector<LL>p=__GET(a,b);
  return query(p);
}

inline bool __brute(LL x,LL y){//极其暴力的判断单点的 p[x] 是否等于 y ,错误率 0.0101 .
  for(LL TC=1;TC<=20;TC++){
    vector<LL>p(n);for(LL i=0;i<n;i++)p[i]=i;
    for(LL i=0;i<n;i++)swap(p[i],p[random(0,(n-1))]);
    for(LL i=0;i<n;i++)if(p[i]==y){swap(p[x],p[i]);break;}
    if(query(p)==0)return 0;
  }
  return 1;
}
inline bool brute(LL x,LL y){//判断单点 p[x] 是否等于 y
  if(X==-1)return __brute(x,y);
  //用一组正确的匹配强行拆解掉原有匹配
  vector<LL>p(n);for(LL i=0;i<n;i++)p[i]=i;
  for(LL i=0;i<n;i++)swap(p[i],p[random(0,(n-1))]);
  for(LL i=0;i<n;i++)if(p[i]==Y){swap(p[X],p[i]);break;}
  for(LL i=0;i<n;i++)if(p[i]==y){swap(p[x],p[i]);break;}
  LL k=query(p);swap(p[x],p[X]);LL _k=query(p);
  return ((k==_k+2)?(1):(0));
}

void solve(vector<LL>a,vector<LL>b,LL l,LL r,LL k){
  if(l==r){link(a[l],b[l]);return ;}
  LL mid=(l+r)>>1;
  if(l==mid){
    assert((r-l+1)==2);
    vector<LL>c=b;swap(c[l],c[r]);
    LL _k=GET(a,c);if(k==_k)return ;//如果相等只有一种可能,那就是这两个元素都不是正确的匹配
    if(k<_k){swap(b,c);swap(k,_k);}//此时(b,k)必然存在至少一组合法正确匹配
    if(k==_k+2){link(a[l],b[l]);link(a[r],b[r]);return ;}//此时找到了两组正确的匹配

    if(brute(a[l],b[l])){link(a[l],b[l]);}
    else {link(a[r],b[r]);}
    return ;
  }
  if((r-l+1)<=4){
    vector<LL>vc_a,vc_b;
    for(LL i=l;i<=mid;i++){vc_a.pb(i);vc_b.pb(i);}
    for(LL i=0;i<SZ(vc_a);i++)swap(vc_a[i],vc_a[random(0,(mid-l))]);
    for(LL i=0;i<SZ(vc_b);i++)swap(vc_b[i],vc_b[random(0,(mid-l))]);
    for(auto x:vc_a)
      for(auto y:vc_b)if(brute(a[x],b[y])){link(a[x],b[y]);return ;}
    solve(a,b,mid+1,r,k);return ;
  }
  for(LL TC=1;TC<=3;TC++){
    /*    vector<LL>c=b;
    while(true){
      for(LL i=l;i<=mid;i++)swap(c[i],c[random(l,mid)]);
      LL fl=0;for(LL i=l;i<=mid;i++)if(b[i]!=c[i]){fl=1;break;}
      if(fl)break;
      }*/
    vector<vector<LL>>vp;
    {
      vector<LL>tmp;
      for(LL i=l;i<=mid;i++)tmp.pb(b[i]);
      vp.pb(tmp);
    }
    vector<LL>c=b;
    while(true){
      for(LL i=l;i<=mid;i++)swap(c[i],c[random(l,mid)]);
      {
	vector<LL>tmp;
	for(LL i=l;i<=mid;i++)tmp.pb(c[i]);
	LL fl=0;
	for(auto u:vp)if(tmp==u){fl=1;break;}
	cerr<<"! l = "<<l<<" mid = "<<mid<<endl;
	if(fl)continue;
	vp.pb(tmp);break;
      }
    }
    LL _k=GET(a,c);
    if(k>_k){solve(a,b,l,mid,k);return ;}
    if(k<_k){solve(a,c,l,mid,_k);return ;}
  }
  solve(a,b,mid+1,r,k);
  return ;
}

void play(LL _n_){
  n=_n_;for(LL t=0;t<n;t++){p[t]=q[t]=1;ans[t]=-1;}
  
  while(true){
    vector<LL>a,b;
    for(LL t=0;t<n;t++){
      if(p[t])a.pb(t);
      if(q[t])b.pb(t);
    }
    cerr<<" SZ(a) = "<<SZ(a)<<" SZ(b) = "<<SZ(b)<<endl;
    assert(SZ(a)==SZ(b));if(!SZ(a))break;
    LL len=SZ(a)-1;if(!len){ans[a[0]]=b[0];break;}
    for(LL t=0;t<=len;t++)swap(b[t],b[random(0,len)]);


    LL k=GET(a,b);
    if(k>TEMP)solve(a,b,0,len,k);
  }
  vector<LL>p(n);
  for(LL i=0;i<n;i++){p[i]=ans[i];assert(ans[i]!=-1);}
  check(p);return ;
}
/*
my test data:
4
2 3 0 1 

*/

詳細信息

Subtask #1:

score: 2
Accepted

Test #1:

score: 2
Accepted
time: 0ms
memory: 3792kb

input:

1 2 816815200

result:

ok accepted: cnt = 5

Test #2:

score: 2
Accepted
time: 0ms
memory: 3892kb

input:

1 3 723182155

result:

ok accepted: cnt = 23

Test #3:

score: 2
Accepted
time: 0ms
memory: 3812kb

input:

1 5 971867682

result:

ok accepted: cnt = 38

Test #4:

score: 2
Accepted
time: 0ms
memory: 3832kb

input:

1 3 887042235

result:

ok accepted: cnt = 33

Test #5:

score: 2
Accepted
time: 0ms
memory: 3764kb

input:

1 3 568659743

result:

ok accepted: cnt = 23

Test #6:

score: 2
Accepted
time: 1ms
memory: 3760kb

input:

1 5 930991667

result:

ok accepted: cnt = 44

Test #7:

score: 2
Accepted
time: 0ms
memory: 3820kb

input:

1 5 185481439

result:

ok accepted: cnt = 45

Test #8:

score: 2
Accepted
time: 0ms
memory: 4116kb

input:

1 5 405685705

result:

ok accepted: cnt = 40

Test #9:

score: 2
Accepted
time: 0ms
memory: 3820kb

input:

1 5 693401039

result:

ok accepted: cnt = 39

Test #10:

score: 2
Accepted
time: 0ms
memory: 3808kb

input:

1 5 570594473

result:

ok accepted: cnt = 37

Subtask #2:

score: 4
Accepted

Test #11:

score: 4
Accepted
time: 0ms
memory: 3776kb

input:

2 2 931107645

result:

ok accepted: cnt = 5

Test #12:

score: 4
Accepted
time: 0ms
memory: 3804kb

input:

2 4 512124670

result:

ok accepted: cnt = 29

Test #13:

score: 4
Accepted
time: 0ms
memory: 3816kb

input:

2 4 793864173

result:

ok accepted: cnt = 31

Test #14:

score: 4
Accepted
time: 0ms
memory: 3892kb

input:

2 7 322910591

result:

ok accepted: cnt = 57

Test #15:

score: 4
Accepted
time: 0ms
memory: 3820kb

input:

2 9 316192686

result:

ok accepted: cnt = 74

Test #16:

score: 4
Accepted
time: 1ms
memory: 3852kb

input:

2 10 350886420

result:

ok accepted: cnt = 90

Test #17:

score: 4
Accepted
time: 0ms
memory: 3760kb

input:

2 10 914937911

result:

ok accepted: cnt = 91

Test #18:

score: 4
Accepted
time: 1ms
memory: 3852kb

input:

2 10 68729974

result:

ok accepted: cnt = 99

Test #19:

score: 4
Accepted
time: 0ms
memory: 4008kb

input:

2 10 15788440

result:

ok accepted: cnt = 63

Test #20:

score: 4
Accepted
time: 0ms
memory: 4116kb

input:

2 10 950846282

result:

ok accepted: cnt = 72

Subtask #3:

score: 0
Wrong Answer

Test #21:

score: 6
Accepted
time: 0ms
memory: 3812kb

input:

3 2 667362636

result:

ok accepted: cnt = 2

Test #22:

score: 6
Accepted
time: 0ms
memory: 4104kb

input:

3 4 890842001

result:

ok accepted: cnt = 29

Test #23:

score: 6
Accepted
time: 0ms
memory: 3880kb

input:

3 3 225277415

result:

ok accepted: cnt = 24

Test #24:

score: 6
Accepted
time: 1ms
memory: 4020kb

input:

3 26 235413642

result:

ok accepted: cnt = 295

Test #25:

score: 6
Accepted
time: 1ms
memory: 3884kb

input:

3 25 139642984

result:

ok accepted: cnt = 256

Test #26:

score: 6
Accepted
time: 0ms
memory: 3860kb

input:

3 30 991911708

result:

ok accepted: cnt = 331

Test #27:

score: 6
Accepted
time: 0ms
memory: 3900kb

input:

3 30 4514256

result:

ok accepted: cnt = 340

Test #28:

score: 6
Accepted
time: 1ms
memory: 3824kb

input:

3 30 157113423

result:

ok accepted: cnt = 320

Test #29:

score: 6
Accepted
time: 0ms
memory: 3768kb

input:

3 30 557648974

result:

ok accepted: cnt = 336

Test #30:

score: 6
Accepted
time: 1ms
memory: 3880kb

input:

3 30 645022468

result:

ok accepted: cnt = 328

Test #31:

score: 6
Accepted
time: 0ms
memory: 4120kb

input:

4 2 427653480

result:

ok accepted: cnt = 2

Test #32:

score: 6
Accepted
time: 0ms
memory: 3856kb

input:

4 3 219860551

result:

ok accepted: cnt = 23

Test #33:

score: 6
Accepted
time: 0ms
memory: 3812kb

input:

4 4 165138325

result:

ok accepted: cnt = 28

Test #34:

score: 0
Wrong Answer
time: 28ms
memory: 3760kb

input:

4 93 525060479

result:

wrong answer too_many_queries

Subtask #4:

score: 0
Wrong Answer

Test #36:

score: 8
Accepted
time: 0ms
memory: 3852kb

input:

4 100 6610818

result:

ok accepted: cnt = 1508

Test #37:

score: 0
Wrong Answer
time: 32ms
memory: 3628kb

input:

4 100 653323659

result:

wrong answer too_many_queries

Subtask #5:

score: 0
Wrong Answer

Test #41:

score: 10
Accepted
time: 0ms
memory: 3804kb

input:

5 2 527801655

result:

ok accepted: cnt = 5

Test #42:

score: 10
Accepted
time: 0ms
memory: 3756kb

input:

5 5 235665947

result:

ok accepted: cnt = 35

Test #43:

score: 10
Accepted
time: 0ms
memory: 3820kb

input:

5 3 648413779

result:

ok accepted: cnt = 24

Test #44:

score: 0
Wrong Answer
time: 32ms
memory: 3944kb

input:

5 272 737778828

result:

wrong answer too_many_queries

Subtask #6:

score: 0
Wrong Answer

Test #51:

score: 10
Accepted
time: 0ms
memory: 3824kb

input:

6 2 183795068

result:

ok accepted: cnt = 5

Test #52:

score: 10
Accepted
time: 0ms
memory: 3816kb

input:

6 5 63668012

result:

ok accepted: cnt = 36

Test #53:

score: 10
Accepted
time: 0ms
memory: 3820kb

input:

6 5 990398365

result:

ok accepted: cnt = 37

Test #54:

score: 0
Wrong Answer
time: 44ms
memory: 3796kb

input:

6 488 942578687

result:

wrong answer too_many_queries

Subtask #7:

score: 0
Wrong Answer

Test #61:

score: 60
Accepted
time: 0ms
memory: 4112kb

input:

7 2 412859550

result:

ok accepted: cnt = 5

Test #62:

score: 60
Accepted
time: 0ms
memory: 3812kb

input:

7 4 892225546

result:

ok accepted: cnt = 34

Test #63:

score: 60
Accepted
time: 0ms
memory: 3816kb

input:

7 4 577686541

result:

ok accepted: cnt = 36

Test #64:

score: 0
Wrong Answer
time: 124ms
memory: 3788kb

input:

7 902 974849567

result:

wrong answer too_many_queries