結果

問題 No.1881 Everything is the same...
ユーザー wasa855wasa855
提出日時 2023-05-11 15:08:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 2,418 bytes
コンパイル時間 3,885 ms
コンパイル使用メモリ 241,912 KB
実行使用メモリ 4,820 KB
最終ジャッジ日時 2023-08-18 09:01:30
合計ジャッジ時間 10,599 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 157 ms
4,700 KB
testcase_11 AC 220 ms
4,604 KB
testcase_12 AC 157 ms
4,628 KB
testcase_13 AC 162 ms
4,568 KB
testcase_14 AC 157 ms
4,612 KB
testcase_15 AC 154 ms
4,820 KB
testcase_16 AC 153 ms
4,532 KB
testcase_17 AC 155 ms
4,692 KB
testcase_18 AC 152 ms
4,760 KB
testcase_19 AC 158 ms
4,532 KB
testcase_20 AC 158 ms
4,592 KB
testcase_21 AC 159 ms
4,592 KB
testcase_22 AC 154 ms
4,740 KB
testcase_23 AC 162 ms
4,660 KB
testcase_24 AC 155 ms
4,520 KB
testcase_25 AC 160 ms
4,632 KB
testcase_26 AC 160 ms
4,628 KB
testcase_27 AC 157 ms
4,772 KB
testcase_28 AC 156 ms
4,612 KB
testcase_29 AC 161 ms
4,768 KB
testcase_30 AC 156 ms
4,536 KB
testcase_31 AC 162 ms
4,708 KB
testcase_32 AC 160 ms
4,548 KB
testcase_33 AC 160 ms
4,564 KB
testcase_34 AC 157 ms
4,696 KB
testcase_35 AC 159 ms
4,520 KB
testcase_36 AC 157 ms
4,632 KB
testcase_37 AC 159 ms
4,616 KB
testcase_38 AC 158 ms
4,628 KB
testcase_39 AC 158 ms
4,644 KB
testcase_40 AC 158 ms
4,640 KB
testcase_41 AC 155 ms
4,680 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 1 ms
4,380 KB
testcase_51 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
#define N 100005
vector<pair<int,int>> factor(int x)
{
	vector<pair<int,int>> ans;
	for(int i=2;i*i<=x;i++)
	{
		if(x%i==0)
		{
			int c=0;
			while(x%i==0) x/=i,c++;
			ans.eb(i,c);
		}
	}
	if(x!=1) ans.eb(x,1);
	return ans;
}
int vis[N];
int mex(const vector<int> &v)
{
	for(int i=0;i<(int)v.size()+3;i++) vis[i]=0;
	for(int i:v) vis[i]=1;
	for(int i=0;;i++) if(!vis[i]) return i;
}
map<vector<vector<int>>,int> sg;
int getmex(vector<vector<int>> state)
{
	if(sg.find(state)!=sg.end()) return sg[state];
	vector<vector<int>> dif;
	int prod=1;
	for(auto v:state)
	{
		vector<int> td;
		for(int j=0;j<(int)v.size();j++)
		{
			int w=v[j]-(j==0?0:v[j-1]);
			td.pb(w+1); prod*=w+1;
		}
		// print(v);
		dif.pb(td);
	}
	// cout<<"* "<<prod<<endl;
	vector<int> trans;
	for(int i=1;i<prod;i++)
	{
		int id=i;
		vector<vector<int>> res;
		for(int j=0;j<(int)state.size();j++)
		{
			vector<int> tmp;
			for(int k=0;k<(int)state[j].size();k++)
			{
				int w=state[j][k]-id%dif[j][k];
				if(w) tmp.pb(w);
				id/=dif[j][k];
			}
			res.pb(tmp);
		}
		sort(res.begin(),res.end());
		trans.pb(getmex(res));
	}
	return sg[state]=mex(trans);
}
int solve(int x)
{
	static map<int,int> vis;
	if(vis.find(x)!=vis.end()) return vis[x];
	map<int,vector<int>> res;
	auto add=[&](int p,int c)
	{
		if(res.find(p)==res.end()) res[p]={};
		res[p].pb(c);
	};
	for(auto [p,c]:factor(x))
	{
		if(p==2)
		{
			if(c>=2) add(2,1);
			if(c>=3) add(2,c-2);
		}
		else
		{
			if(c>=2) add(p,c-1);
			for(auto [w,t]:factor(p-1)) add(w,t);
		}
	}
	vector<vector<int>> state;
	for(auto [p,v]:res)
	{
		vector<int> tmp=v;
		sort(v.begin(),v.end());
		state.pb(v);
	}
	sort(state.begin(),state.end());
	return vis[x]=getmex(state);
}
signed main()
{
	int n=read(),ans=0;
	for(int i=1;i<=n;i++) ans^=solve(read());
	if(ans) cout<<"Y\n";
	else cout<<"X\n";
	return 0;
}


0