Particle

競技プログラミングについての雑記

CODE FESTIVAL 2016 Grand Final G

FESTIVA (256^0 の位)
+ (AVITSE+F) + (AVITSE+FF)+ (AVITSE+FFFF) +... +(AVITSE+FF...FF) (256^1 の位)
+ (AVITS + E) + ... (AVITS + EE...EE) (256^2 の位)
...
+ AA...AA (256^7 の位)
のような文字列を考えると、256進数と対応する。
文字数は、高々 1960 + 255*8 = 4000 文字となり制約を満たす。(256^8 >= 1e9 なので、実際にはこれよりも文字数が小さく構成される。)

#define M 256
int main(){
	ll x;
	cin>>x;
	vector<int> res; res.reserve(5000);
	rep(i, 7) res.pb(i);
	rep(i, 8){
		ll y = x%M;
		if(i==7) y = x;
		rep(k, y) res.pb(7);
		x /= M;
		if(i==7) break;
		rep(j, 8){
			for(int k = 6; k >= i+1; k--) res.pb(k);
			rep(k, 1<<j) res.pb(i);
		}
	}
	string s, fes = "FESTIVAL";
	rep(i, res.size()) s += fes[res[i]];
	cout<<s<<endl;
	return 0;
}