Submission #23505178


Source Code Expand

#include<bits/stdc++.h>

#define ll long long 

using namespace std;

int read()
{
	int a=0,f=1,c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')f=-1;
		c=getchar();
	}
	while(isdigit(c))
	{
		a=a*10+c-'0';
		c=getchar();
	}
	return a*f;
}

const int N=1e5+10;

ll p,a,b;
bool vis[N];

int main()
{
//	freopen("1.in","r",stdin);
	
	p=read();
	a=read();b=read();
	
	ll x=1;int cir=1;
	for(;;++cir)
	{
		x=x*a%p;
		if(x==1)break;
	}
	if(cir%2==1)
	{
		swap(a,b);
		cir=(p-1)/cir;
	}
	
	ll ia=1,ib=1;
	for(int i=1;i<=p-2;++i)ia=ia*a%p;
	for(int i=1;i<=p-2;++i)ib=ib*b%p;
	
	x=1;
	vector<ll> ans;
	vis[x]=1;ans.push_back(x);
	if((p-1)/cir==1)
	{
		for(int i=1;i<=cir;++i)
		{
			x=x*a%p;
			if(vis[x] && !(i==cir && x==1)){puts("No");return 0;}
			vis[x]=1;ans.push_back(x);
		}
	}
	else
	{
		x=x*b%p;
		if(vis[x]){puts("No");return 0;}
		vis[x]=1;ans.push_back(x);
		
		for(int i=1;i<=cir;++i)
		{
			int t=i%2==1?b:ib;
			for(int j=1;j<=(p-1)/cir-2;++j)
			{
				x=x*t%p;
				if(vis[x]){puts("No");return 0;}
				vis[x]=1;ans.push_back(x);
			}
			if(i<cir)
			{
				x=x*a%p;
				if(vis[x]){puts("No");return 0;}
				vis[x]=1;ans.push_back(x);
			}
		}
		
		x=x*ib%p;
		if(vis[x]){puts("No");return 0;}
		vis[x]=1;ans.push_back(x);
		
		for(int i=1;i<=cir-1;++i)
		{
			x=x*ia%p;
			if(vis[x] && !(i==cir-1 && x==1)){puts("No");return 0;}
			vis[x]=1;ans.push_back(x);
		}
	}
	
	puts("Yes");
	for(int i=0;i<(int)ans.size();++i)printf("%lld ",ans[i]);
	puts("");
	
	return 0;
}

Submission Info

Submission Time
Task D - Hamiltonian Cycle
User WhereIsDodoco
Language C++ (GCC 9.2.1)
Score 700
Code Size 1575 Byte
Status AC
Exec Time 29 ms
Memory 4236 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 4
AC × 50
Set Name Test Cases
Sample 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 01_sample_04.txt
All 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 01_sample_04.txt, 02_random_no_01.txt, 02_random_no_02.txt, 02_random_no_03.txt, 02_random_no_04.txt, 02_random_no_05.txt, 02_random_no_06.txt, 02_random_no_07.txt, 02_random_no_08.txt, 02_random_no_09.txt, 02_random_no_10.txt, 03_random_yes_01.txt, 03_random_yes_02.txt, 03_random_yes_03.txt, 03_random_yes_04.txt, 03_random_yes_05.txt, 03_random_yes_06.txt, 03_random_yes_07.txt, 03_random_yes_08.txt, 03_random_yes_09.txt, 03_random_yes_10.txt, 03_random_yes_11.txt, 03_random_yes_12.txt, 03_random_yes_13.txt, 03_random_yes_14.txt, 03_random_yes_15.txt, 03_random_yes_16.txt, 03_random_yes_17.txt, 03_random_yes_18.txt, 03_random_yes_19.txt, 03_random_yes_20.txt, 04_no_with_1_01.txt, 04_no_with_1_02.txt, 04_no_with_1_03.txt, 04_no_with_1_04.txt, 04_no_with_1_05.txt, 05_yes_with_1_01.txt, 05_yes_with_1_02.txt, 05_yes_with_1_03.txt, 05_yes_with_1_04.txt, 05_yes_with_1_05.txt, 06_maxsize_01.txt, 06_maxsize_02.txt, 07_handmade_01.txt, 07_handmade_02.txt, 07_handmade_03.txt, 07_handmade_04.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 9 ms 3544 KiB
01_sample_02.txt AC 2 ms 3484 KiB
01_sample_03.txt AC 1 ms 3456 KiB
01_sample_04.txt AC 2 ms 3516 KiB
02_random_no_01.txt AC 13 ms 3784 KiB
02_random_no_02.txt AC 6 ms 3612 KiB
02_random_no_03.txt AC 10 ms 3496 KiB
02_random_no_04.txt AC 13 ms 3668 KiB
02_random_no_05.txt AC 2 ms 3456 KiB
02_random_no_06.txt AC 3 ms 3564 KiB
02_random_no_07.txt AC 9 ms 3800 KiB
02_random_no_08.txt AC 8 ms 3588 KiB
02_random_no_09.txt AC 7 ms 3632 KiB
02_random_no_10.txt AC 5 ms 3536 KiB
03_random_yes_01.txt AC 12 ms 3688 KiB
03_random_yes_02.txt AC 29 ms 4072 KiB
03_random_yes_03.txt AC 15 ms 4236 KiB
03_random_yes_04.txt AC 12 ms 3656 KiB
03_random_yes_05.txt AC 15 ms 3804 KiB
03_random_yes_06.txt AC 18 ms 4148 KiB
03_random_yes_07.txt AC 6 ms 3668 KiB
03_random_yes_08.txt AC 10 ms 3576 KiB
03_random_yes_09.txt AC 14 ms 3700 KiB
03_random_yes_10.txt AC 13 ms 3612 KiB
03_random_yes_11.txt AC 19 ms 3696 KiB
03_random_yes_12.txt AC 11 ms 3672 KiB
03_random_yes_13.txt AC 22 ms 4088 KiB
03_random_yes_14.txt AC 9 ms 3584 KiB
03_random_yes_15.txt AC 14 ms 3792 KiB
03_random_yes_16.txt AC 8 ms 3680 KiB
03_random_yes_17.txt AC 13 ms 3756 KiB
03_random_yes_18.txt AC 24 ms 4016 KiB
03_random_yes_19.txt AC 17 ms 3772 KiB
03_random_yes_20.txt AC 21 ms 4108 KiB
04_no_with_1_01.txt AC 6 ms 3608 KiB
04_no_with_1_02.txt AC 5 ms 3704 KiB
04_no_with_1_03.txt AC 5 ms 3516 KiB
04_no_with_1_04.txt AC 12 ms 3676 KiB
04_no_with_1_05.txt AC 7 ms 3524 KiB
05_yes_with_1_01.txt AC 19 ms 3640 KiB
05_yes_with_1_02.txt AC 15 ms 3768 KiB
05_yes_with_1_03.txt AC 18 ms 4016 KiB
05_yes_with_1_04.txt AC 25 ms 4148 KiB
05_yes_with_1_05.txt AC 16 ms 3700 KiB
06_maxsize_01.txt AC 28 ms 4036 KiB
06_maxsize_02.txt AC 12 ms 3724 KiB
07_handmade_01.txt AC 2 ms 3580 KiB
07_handmade_02.txt AC 3 ms 3536 KiB
07_handmade_03.txt AC 2 ms 3592 KiB
07_handmade_04.txt AC 2 ms 3440 KiB