結果
問題 |
No.254 文字列の構成
|
ユーザー |
![]() |
提出日時 | 2015-07-25 00:03:45 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 926 bytes |
コンパイル時間 | 1,499 ms |
コンパイル使用メモリ | 161,732 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-16 01:18:23 |
合計ジャッジ時間 | 5,306 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 2 |
other | WA * 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"); cout << s << "(" << i << ")" << " " << f(s) << "=" << f(i) << endl; 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; }