QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#587755#8952. 解谜游戏Kevin5307100 ✓17ms8328kbC++202.5kb2024-09-24 21:28:072024-09-24 21:28:08

Judging History

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

  • [2024-09-24 21:28:08]
  • 评测
  • 测评结果:100
  • 用时:17ms
  • 内存:8328kb
  • [2024-09-24 21:28:07]
  • 提交

answer

#include "puzzle.h"
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<random>
#define N 1000
using namespace std;
struct reads
{
	int x,y;
};
vector<reads>p[N+1];
int tn,n,length,tong[N+1],rd[N+1];
bool used[N+1];
unsigned long long seed=998244353;
vector<int>E[N+1];
unsigned long long get_rand()
{
	seed^=(seed<<7);
	seed^=(seed>>11);
	seed^=(seed<<17);
	return seed;
}
int get(int x)
{
	if (x>tn) x-=tn;
	if (x<1) x+=tn;
	return x;
}
void add_edge(int x,int y)
{
	E[x].push_back(y),E[y].push_back(x);
	return;
}
void solve(vector<reads>sp,int res)
{
	if (!res) return;
	if (sp.size()==1)
	{
		for (int i=0;i<sp.size();++i) add_edge(sp[i].x,sp[i].y);
		return;
	}
	vector<reads>A;
	vector<reads>B;
	int mid=sp.size()>>1,d;
	vector<int>tp(n);
	for (int i=1;i<=n;++i) tp[i-1]=rd[i];
	for (int i=0;i<mid;++i) A.push_back(sp[i]),tp[sp[i].x-1]=rd[sp[i].y],tp[sp[i].y-1]=rd[sp[i].x];
	for (int i=mid;i<sp.size();++i) B.push_back(sp[i]);
	d=query(tp),solve(A,d),solve(B,res-d);
	return;
}
void dfs(int x)
{
	used[x]=1,tong[++length]=x;
	for (int i=0;i<E[x].size();++i)
		if (!used[E[x][i]])
			dfs(E[x][i]);
	return;
}
void play(int sn)
{
	n=sn;
	vector<reads>tp;
	vector<int>sp(n);
	vector<int>ans(n);
	for (int i=0;i<n;++i) sp[i]=i;
	mt19937_64 rng(114514);
	while (1)
	{
		shuffle(sp.begin(),sp.end(),rng);
		if (!query(sp)) break;
	}
	for (int i=1;i<=n;++i) rd[i]=sp[i-1];
	if (!(n&1))
	{
		tn=n-1;
		for (int i=1;i<=n-1;++i)
		{
			p[i].push_back((reads){i,n});
			for (int j=1;j<=(n>>1)-1;++j) p[i].push_back((reads){get(i-j),get(i+j)});
		}
	}
	else
	{
		tn=n;
		for (int i=1;i<=n;++i)
			for (int j=1;j<=(n>>1);++j)
				p[i].push_back((reads){get(i-j),get(i+j)});
	}
	for (int i=1;i<=n;++i)
		if (!p[i].empty())
		{
			tp.clear();
			for (int j=0;j<p[i].size();++j)
				if (E[p[i][j].x].size()<=1&&E[p[i][j].y].size()<=1)
					tp.push_back(p[i][j]);
			if (!tp.empty())
			{
				for (int j=1;j<=n;++j) sp[j-1]=rd[j];
				for (int j=0;j<tp.size();++j) sp[tp[j].x-1]=rd[tp[j].y],sp[tp[j].y-1]=rd[tp[j].x];
				solve(tp,query(sp));
			}
		}
	for (int i=1;i<=n;++i)
		if (!used[i])
		{
			length=0,dfs(i);
			for (int j=1;j<=n;++j) sp[j-1]=rd[j];
			for (int j=1;j<=length;++j) sp[tong[j]-1]=rd[tong[j%length+1]];
			if (query(sp))
			{
				for (int j=1;j<=length;++j) ans[tong[j]-1]=rd[tong[j%length+1]];
			}
			else
			{
				for (int j=1;j<=length;++j) ans[tong[j%length+1]-1]=rd[tong[j]];
			}
		}
	check(ans);
	return;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 2
Accepted

Test #1:

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

input:

1 2 816815200

result:

ok accepted: cnt = 4

Test #2:

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

input:

1 3 723182155

result:

ok accepted: cnt = 7

Test #3:

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

input:

1 5 971867682

result:

ok accepted: cnt = 14

Test #4:

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

input:

1 3 887042235

result:

ok accepted: cnt = 5

Test #5:

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

input:

1 3 568659743

result:

ok accepted: cnt = 7

Test #6:

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

input:

1 5 930991667

result:

ok accepted: cnt = 8

Test #7:

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

input:

1 5 185481439

result:

ok accepted: cnt = 14

Test #8:

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

input:

1 5 405685705

result:

ok accepted: cnt = 7

Test #9:

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

input:

1 5 693401039

result:

ok accepted: cnt = 13

Test #10:

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

input:

1 5 570594473

result:

ok accepted: cnt = 10

Subtask #2:

score: 4
Accepted

Test #11:

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

input:

2 2 931107645

result:

ok accepted: cnt = 4

Test #12:

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

input:

2 4 512124670

result:

ok accepted: cnt = 8

Test #13:

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

input:

2 4 793864173

result:

ok accepted: cnt = 10

Test #14:

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

input:

2 7 322910591

result:

ok accepted: cnt = 18

Test #15:

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

input:

2 9 316192686

result:

ok accepted: cnt = 18

Test #16:

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

input:

2 10 350886420

result:

ok accepted: cnt = 33

Test #17:

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

input:

2 10 914937911

result:

ok accepted: cnt = 24

Test #18:

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

input:

2 10 68729974

result:

ok accepted: cnt = 29

Test #19:

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

input:

2 10 15788440

result:

ok accepted: cnt = 26

Test #20:

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

input:

2 10 950846282

result:

ok accepted: cnt = 25

Subtask #3:

score: 6
Accepted

Test #21:

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

input:

3 2 667362636

result:

ok accepted: cnt = 3

Test #22:

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

input:

3 4 890842001

result:

ok accepted: cnt = 8

Test #23:

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

input:

3 3 225277415

result:

ok accepted: cnt = 6

Test #24:

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

input:

3 26 235413642

result:

ok accepted: cnt = 78

Test #25:

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

input:

3 25 139642984

result:

ok accepted: cnt = 78

Test #26:

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

input:

3 30 991911708

result:

ok accepted: cnt = 96

Test #27:

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

input:

3 30 4514256

result:

ok accepted: cnt = 109

Test #28:

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

input:

3 30 157113423

result:

ok accepted: cnt = 96

Test #29:

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

input:

3 30 557648974

result:

ok accepted: cnt = 107

Test #30:

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

input:

3 30 645022468

result:

ok accepted: cnt = 99

Test #31:

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

input:

4 2 427653480

result:

ok accepted: cnt = 3

Test #32:

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

input:

4 3 219860551

result:

ok accepted: cnt = 7

Test #33:

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

input:

4 4 165138325

result:

ok accepted: cnt = 8

Test #34:

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

input:

4 93 525060479

result:

ok accepted: cnt = 421

Test #35:

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

input:

4 99 829735778

result:

ok accepted: cnt = 467

Subtask #4:

score: 8
Accepted

Test #36:

score: 8
Accepted
time: 1ms
memory: 4080kb

input:

4 100 6610818

result:

ok accepted: cnt = 464

Test #37:

score: 8
Accepted
time: 1ms
memory: 3920kb

input:

4 100 653323659

result:

ok accepted: cnt = 460

Test #38:

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

input:

4 100 268513130

result:

ok accepted: cnt = 462

Test #39:

score: 8
Accepted
time: 1ms
memory: 3888kb

input:

4 100 479581529

result:

ok accepted: cnt = 442

Test #40:

score: 8
Accepted
time: 1ms
memory: 4080kb

input:

4 100 119844914

result:

ok accepted: cnt = 467

Subtask #5:

score: 10
Accepted

Test #41:

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

input:

5 2 527801655

result:

ok accepted: cnt = 4

Test #42:

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

input:

5 5 235665947

result:

ok accepted: cnt = 15

Test #43:

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

input:

5 3 648413779

result:

ok accepted: cnt = 6

Test #44:

score: 10
Accepted
time: 2ms
memory: 4448kb

input:

5 272 737778828

result:

ok accepted: cnt = 1586

Test #45:

score: 10
Accepted
time: 2ms
memory: 4532kb

input:

5 278 173436130

result:

ok accepted: cnt = 1653

Test #46:

score: 10
Accepted
time: 2ms
memory: 4808kb

input:

5 300 997862299

result:

ok accepted: cnt = 1766

Test #47:

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

input:

5 300 764271855

result:

ok accepted: cnt = 1783

Test #48:

score: 10
Accepted
time: 2ms
memory: 4500kb

input:

5 300 428892383

result:

ok accepted: cnt = 1835

Test #49:

score: 10
Accepted
time: 2ms
memory: 4528kb

input:

5 300 166706392

result:

ok accepted: cnt = 1747

Test #50:

score: 10
Accepted
time: 2ms
memory: 4504kb

input:

5 300 843444435

result:

ok accepted: cnt = 1797

Subtask #6:

score: 10
Accepted

Test #51:

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

input:

6 2 183795068

result:

ok accepted: cnt = 4

Test #52:

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

input:

6 5 63668012

result:

ok accepted: cnt = 9

Test #53:

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

input:

6 5 990398365

result:

ok accepted: cnt = 10

Test #54:

score: 10
Accepted
time: 4ms
memory: 4884kb

input:

6 488 942578687

result:

ok accepted: cnt = 3201

Test #55:

score: 10
Accepted
time: 4ms
memory: 4904kb

input:

6 475 915148470

result:

ok accepted: cnt = 3118

Test #56:

score: 10
Accepted
time: 5ms
memory: 4996kb

input:

6 500 736505651

result:

ok accepted: cnt = 3351

Test #57:

score: 10
Accepted
time: 4ms
memory: 4956kb

input:

6 500 352417213

result:

ok accepted: cnt = 3291

Test #58:

score: 10
Accepted
time: 4ms
memory: 5160kb

input:

6 500 80534667

result:

ok accepted: cnt = 3315

Test #59:

score: 10
Accepted
time: 4ms
memory: 5020kb

input:

6 500 811975157

result:

ok accepted: cnt = 3308

Test #60:

score: 10
Accepted
time: 4ms
memory: 5148kb

input:

6 500 471392863

result:

ok accepted: cnt = 3315

Subtask #7:

score: 60
Accepted

Test #61:

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

input:

7 2 412859550

result:

ok accepted: cnt = 4

Test #62:

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

input:

7 4 892225546

result:

ok accepted: cnt = 10

Test #63:

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

input:

7 4 577686541

result:

ok accepted: cnt = 7

Test #64:

score: 60
Accepted
time: 14ms
memory: 7636kb

input:

7 902 974849567

result:

ok accepted: cnt = 6781

Test #65:

score: 60
Accepted
time: 14ms
memory: 7776kb

input:

7 939 155203710

result:

ok accepted: cnt = 7014

Test #66:

score: 60
Accepted
time: 12ms
memory: 8124kb

input:

7 1000 253107507

result:

ok accepted: cnt = 7566

Test #67:

score: 60
Accepted
time: 13ms
memory: 7984kb

input:

7 1000 882029420

result:

ok accepted: cnt = 7607

Test #68:

score: 60
Accepted
time: 16ms
memory: 8128kb

input:

7 1000 199421982

result:

ok accepted: cnt = 7641

Test #69:

score: 60
Accepted
time: 16ms
memory: 8004kb

input:

7 1000 749220884

result:

ok accepted: cnt = 7634

Test #70:

score: 60
Accepted
time: 13ms
memory: 8032kb

input:

7 1000 729055050

result:

ok accepted: cnt = 7584

Test #71:

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

input:

7 2 375338281

result:

ok accepted: cnt = 3

Test #72:

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

input:

7 5 914443594

result:

ok accepted: cnt = 12

Test #73:

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

input:

7 5 310479620

result:

ok accepted: cnt = 11

Test #74:

score: 60
Accepted
time: 12ms
memory: 7976kb

input:

7 982 660842623

result:

ok accepted: cnt = 7442

Test #75:

score: 60
Accepted
time: 16ms
memory: 8272kb

input:

7 985 92435101

result:

ok accepted: cnt = 7448

Test #76:

score: 60
Accepted
time: 12ms
memory: 8036kb

input:

7 1000 901527471

result:

ok accepted: cnt = 7564

Test #77:

score: 60
Accepted
time: 12ms
memory: 8040kb

input:

7 1000 891945482

result:

ok accepted: cnt = 7595

Test #78:

score: 60
Accepted
time: 17ms
memory: 8128kb

input:

7 1000 461988571

result:

ok accepted: cnt = 7616

Test #79:

score: 60
Accepted
time: 16ms
memory: 8012kb

input:

7 1000 588921486

result:

ok accepted: cnt = 7623

Test #80:

score: 60
Accepted
time: 16ms
memory: 7992kb

input:

7 1000 819181186

result:

ok accepted: cnt = 7575

Test #81:

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

input:

7 2 509390821

result:

ok accepted: cnt = 4

Test #82:

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

input:

7 3 932973010

result:

ok accepted: cnt = 5

Test #83:

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

input:

7 3 704198002

result:

ok accepted: cnt = 7

Test #84:

score: 60
Accepted
time: 12ms
memory: 8316kb

input:

7 996 844688748

result:

ok accepted: cnt = 7535

Test #85:

score: 60
Accepted
time: 14ms
memory: 7736kb

input:

7 935 983758765

result:

ok accepted: cnt = 7059

Test #86:

score: 60
Accepted
time: 13ms
memory: 8044kb

input:

7 1000 560957955

result:

ok accepted: cnt = 7568

Test #87:

score: 60
Accepted
time: 13ms
memory: 8052kb

input:

7 1000 381616996

result:

ok accepted: cnt = 7584

Test #88:

score: 60
Accepted
time: 16ms
memory: 8028kb

input:

7 1000 607168013

result:

ok accepted: cnt = 7605

Test #89:

score: 60
Accepted
time: 17ms
memory: 8096kb

input:

7 1000 755432541

result:

ok accepted: cnt = 7598

Test #90:

score: 60
Accepted
time: 13ms
memory: 8084kb

input:

7 1000 675700852

result:

ok accepted: cnt = 7630

Test #91:

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

input:

7 2 91873452

result:

ok accepted: cnt = 4

Test #92:

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

input:

7 4 336570576

result:

ok accepted: cnt = 11

Test #93:

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

input:

7 4 617201184

result:

ok accepted: cnt = 9

Test #94:

score: 60
Accepted
time: 7ms
memory: 7608kb

input:

7 904 396880646

result:

ok accepted: cnt = 6714

Test #95:

score: 60
Accepted
time: 14ms
memory: 7584kb

input:

7 906 970970547

result:

ok accepted: cnt = 6740

Test #96:

score: 60
Accepted
time: 12ms
memory: 8120kb

input:

7 1000 960558936

result:

ok accepted: cnt = 7583

Test #97:

score: 60
Accepted
time: 13ms
memory: 8120kb

input:

7 1000 238446836

result:

ok accepted: cnt = 7628

Test #98:

score: 60
Accepted
time: 12ms
memory: 8052kb

input:

7 1000 897094536

result:

ok accepted: cnt = 7547

Test #99:

score: 60
Accepted
time: 16ms
memory: 7996kb

input:

7 1000 820891454

result:

ok accepted: cnt = 7539

Test #100:

score: 60
Accepted
time: 17ms
memory: 8328kb

input:

7 1000 586475353

result:

ok accepted: cnt = 7630