結果

問題 No.254 文字列の構成
コンテスト
ユーザー itezpace
提出日時 2016-10-29 09:14:43
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 528 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 554 ms
コンパイル使用メモリ 79,984 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-18 06:29:33
合計ジャッジ時間 2,314 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(){
  int N=0;cin>>N;
  string s1;
  int cn1=97;
  while(1){
    int M=sqrt(N);
    char c1=cn1;
    string s2;
    s2+=c1;
    int f=1;
    for(int i=1;i<M;++i){
      int cn2=cn1;
      if(f==1) cn2+=1;
      char c=cn2;
      s2.insert(s2.begin(),c);
      s2+=c;
      f*=-1;
    }
    s1+=s2;
    N-=M*M;
    cn1+=2;
    if(N==1){
      char c=cn1;
      s1+=c;
      break;
    } else if(N==0){
      break;
    }
  }
  cout<<s1<<endl;
}
0