結果

問題 No.2893 Minahoshi (Hard)
ユーザー 👑 kmjpkmjp
提出日時 2024-09-16 23:47:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,723 bytes
コンパイル時間 2,634 ms
コンパイル使用メモリ 213,724 KB
実行使用メモリ 56,112 KB
最終ジャッジ日時 2024-09-16 23:47:28
合計ジャッジ時間 12,564 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
40,064 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 29 ms
44,792 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'void solve()':
main.cpp:6:28: warning: 'x' may be used uninitialized [-Wmaybe-uninitialized]
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                            ^
main.cpp:69:23: note: 'x' was declared here
   69 |         int i,j,k,l,r,x,y; string s;
      |                       ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int T,N;
ll F[28];

vector<int> L[20] = {
	{},
	{1},
	{1,2},
	{2,3},
	{3,4},
	{3,5},
	{5,6},
	{6,7},
	{4,5,6,8},
	{5,9},
	{7,10},
	{9,11},
	{1,4,6,12},
	{1,3,4,13},
	{1,3,5,14},
	{14,15},
	{4,13,15,16},
	{14,17},
	{11,18},
	{1,2,6,19},
};

int nex[4<<20];
int add[4<<20];
int addf[4<<20];
int pos[4<<20];

template<int um> class UF {
	public:
	vector<int> par,rank,cnt,G[um];
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit(int num=um) {int i; FOR(i,num) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
	void dump(int num=um) { //グループ分けした配列を作る
		int i;
		FOR(i,num) G[i].clear();
		FOR(i,num) G[operator[](i)].push_back(i);
	}
};
UF<1<<20> uf;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	FOR(i,20) {
		F[i]=(1LL<<(i+1))+i;
		//cout<<i<<" "<<F[i]<<endl;
	}
	
	cin>>T;
	while(T--) {
		cin>>N;
		if(N==2) {
			cout<<"ab"<<endl;
			continue;
		}
		if(N==3) {
			cout<<"abb"<<endl;
			continue;
		}
		if(N==4) {
			cout<<"aabb"<<endl;
			continue;
		}
		if(N==5) {
			cout<<"aabba"<<endl;
			continue;
		}
		int tar=0;
		FOR(i,28) {
			if(N<=F[i]) {
				x=i-1;
				break;
			}
		}
		vector<int> V;
		FOR(i,x) V.push_back(0);
		V.push_back(1);
		FOR(i,(2<<x)-(x+1)) {
			int add=0;
			FORR(a,L[x+1]) add^=V[V.size()-a];
			V.push_back(add);
		}
		FOR(i,x) V.push_back(0);
		reverse(ALL(V));
		V.push_back(V[x]);
		/*
		cout<<N<<" "<<x<<" ";
		FORR(v,V) cout<<v;
		cout<<"  : ";
		*/
		uf.reinit(4<<x);
		FOR(i,4<<x) nex[i]=add[i]=addf[i]=0, pos[i]=-1;
		FOR(i,(2<<x)) {
			int a=0;
			FOR(j,x+2) a=a*2+V[i+j];
			//cout<<a<<" ";
			nex[a]=-1;
			pos[a%(2<<x)]=i+1;
		}
		FOR(i,(4<<x)) if(nex[i]==0) {
			int a=i*2%(4<<x);
			int b=(i*2+1)%(4<<x);
			if(nex[a]==-1) nex[i]=b;
			else nex[i]=a;
			uf(i,nex[i]);
		}
		int nadd=N-V.size();
		int st=-1;
		FOR(i,(4<<x)) if(nex[i]!=-1&&uf[i]==i) {
			addf[i/2]=uf.count(i);
			add[i/2]=min(nadd,addf[i/2]);
			nadd-=add[i/2];
			if(nadd==0) {
				//cout<<"$"<<i<<endl;
				st=i;
				break;
			}
		}
		y=pos[st/2];
		//FORR(a,V) cout<<a<<" ";
		rotate(V.begin(),V.begin()+y,V.end());
		rotate(V.begin(),V.begin()+(x+1),V.end());
		/*
		cout<<" ["<<y<<"] ";
		FORR(a,V) cout<<a<<" ";
		cout<<endl;
		*/
		y=0;
		FOR(i,V.size()) {
			cout<<(char)('a'+V[i]);
			y=(y*2+V[i])%(2<<x);
			if(i>=x+1) {
				int cur=y;
				//cout<<"("<<add[y]<<")";
				FOR(j,add[y]) {
					if(nex[(cur*2)%(4<<x)]>=0) {
						cur=nex[(cur*2)%(4<<x)];
					}
					else {
						cur=nex[(cur*2+1)%(4<<x)];
					}
					cout<<(char)('a'+cur%2);
					cur/=2;
				}
			}
		}
		//FORR(a,V) cout<<a;
		cout<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0