結果
| 問題 | No.254 文字列の構成 | 
| コンテスト | |
| ユーザー |  kyuridenamida | 
| 提出日時 | 2015-07-25 00:04:21 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 4 ms / 5,000 ms | 
| コード長 | 856 bytes | 
| コンパイル時間 | 1,500 ms | 
| コンパイル使用メモリ | 160,220 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-16 01:32:28 | 
| 合計ジャッジ時間 | 2,803 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 30 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int f(string s){
	int cnt = 0;
	for(int i = 0 ; i < s.size() ; i++){
		int l = i , r = i;
		while( l >= 0 && r < s.size() && s[l] == s[r] ){
			cnt++;
			l--;
			r++;
		}
		l = i , r = i+1;
		while( l >= 0 && r < s.size() && s[l] == s[r] ){
			cnt++;
			l--;
			r++;
		}
	}
	return cnt;
}
int f(int n){
	int ans = 0;
	
	
	for(int i = 1 ; i <= n ; i++){
		ans += (i+1)/2;
	}
	return ans;
}
int main(){
	string s;
	int p = 0;
	for(int i = 1 ; i <= 30 ; i++){
		s += (i&1?"a":"b");
		p = f(s);
	}
	int N;
	cin >> N;
	string res;
	int hoge = 0;
	while(N){
		int l = 1 , r = 100000;
		while( l != r ){
			int m = (l+r+1)/2;
			if( f(m) > N ) {
				r = m-1;
			}else{	
				l = m;
			}
		}
		int s = f(l);
		N -= s;
		for(int j = 0 ; j < l ; j++)
			res += hoge + 'a' + j % 2;
		hoge += 2;
	}
	cout << res << endl;
}
            
            
            
        