結果

問題 No.2893 Minahoshi (Hard)
ユーザー 👑 kmjpkmjp
提出日時 2024-09-17 00:31:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 3,548 bytes
コンパイル時間 2,655 ms
コンパイル使用メモリ 215,200 KB
実行使用メモリ 56,084 KB
最終ジャッジ日時 2024-09-17 00:31:39
合計ジャッジ時間 7,600 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
40,468 KB
testcase_01 AC 70 ms
47,756 KB
testcase_02 AC 67 ms
48,060 KB
testcase_03 AC 51 ms
48,468 KB
testcase_04 AC 48 ms
47,672 KB
testcase_05 AC 63 ms
49,048 KB
testcase_06 AC 45 ms
46,372 KB
testcase_07 AC 44 ms
47,592 KB
testcase_08 AC 43 ms
46,728 KB
testcase_09 AC 65 ms
48,688 KB
testcase_10 AC 53 ms
48,196 KB
testcase_11 AC 51 ms
48,416 KB
testcase_12 AC 60 ms
48,808 KB
testcase_13 AC 43 ms
47,940 KB
testcase_14 AC 47 ms
55,092 KB
testcase_15 AC 27 ms
47,016 KB
testcase_16 AC 53 ms
48,140 KB
testcase_17 AC 51 ms
47,912 KB
testcase_18 AC 36 ms
48,600 KB
testcase_19 AC 52 ms
48,224 KB
testcase_20 AC 36 ms
47,108 KB
testcase_21 AC 41 ms
48,168 KB
testcase_22 AC 34 ms
47,308 KB
testcase_23 AC 45 ms
48,820 KB
testcase_24 AC 39 ms
47,724 KB
testcase_25 AC 27 ms
47,260 KB
testcase_26 AC 20 ms
46,628 KB
testcase_27 AC 45 ms
47,140 KB
testcase_28 AC 54 ms
49,040 KB
testcase_29 AC 59 ms
48,240 KB
testcase_30 AC 64 ms
48,940 KB
testcase_31 AC 40 ms
47,828 KB
testcase_32 AC 41 ms
47,812 KB
testcase_33 AC 65 ms
48,772 KB
testcase_34 AC 63 ms
48,820 KB
testcase_35 AC 39 ms
48,612 KB
testcase_36 AC 40 ms
48,208 KB
testcase_37 AC 68 ms
49,412 KB
testcase_38 AC 39 ms
47,504 KB
testcase_39 AC 41 ms
47,872 KB
testcase_40 AC 41 ms
47,884 KB
testcase_41 AC 40 ms
48,480 KB
testcase_42 AC 65 ms
56,084 KB
testcase_43 AC 73 ms
48,500 KB
testcase_44 AC 62 ms
48,484 KB
testcase_45 AC 63 ms
48,504 KB
testcase_46 AC 66 ms
55,820 KB
testcase_47 AC 65 ms
49,476 KB
testcase_48 AC 39 ms
48,172 KB
testcase_49 AC 38 ms
47,364 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
	}
	
	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);
		}
		reverse(ALL(V));
		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)%V.size()];
			nex[a]=-1;
			a=0;
			FOR(j,x+1) a=a*2+V[(i+j)%V.size()];
			pos[a]=i;
		}
		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()+x+1);
		int st=-1;
		FOR(i,2<<x) {
			int a=0;
			FOR(j,x+1) a=a*2+V[(i+j)%V.size()];
			int b=-1;
			if(nex[a*2+1]!=-1&&uf[a*2+1]==a*2+1) b=a*2+1;
			if(nex[a*2+0]!=-1&&uf[a*2+0]==a*2+0) b=a*2+0;
			if(b!=-1) {
				addf[a]=uf.count(b);
				add[a]=min(nadd,addf[a]);
				nadd-=add[a];
				pos[a]=i;
				if(nadd==0) {
					rotate(V.begin(),V.begin()+i,V.end());
					break;
				}
			}
		}
		
		FOR(i,x+1) V.push_back(V[i]);
		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;
				FOR(j,add[y]) {
					if(nex[(cur*2)%(4<<x)]>=0) {
						cur=(cur*2)%(2<<x);
					}
					else {
						cur=(cur*2+1)%(2<<x);
					}
					cout<<(char)('a'+cur%2);
					
				}
			}
		}
		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