結果

問題 No.1881 Everything is the same...
ユーザー wasa855wasa855
提出日時 2023-05-11 15:00:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,327 bytes
コンパイル時間 3,099 ms
コンパイル使用メモリ 240,960 KB
実行使用メモリ 268,452 KB
最終ジャッジ日時 2023-08-18 08:57:33
合計ジャッジ時間 8,821 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 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,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
		}
		dif.pb(td);
	}
	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++)
			{
				tmp.pb(state[j][k]-id%dif[j][k]);
				id/=dif[j][k];
			}
			res.pb(tmp);
		}
		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(tmp);
	}
	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