結果

問題 No.205 マージして辞書順最小
ユーザー itezpaceitezpace
提出日時 2016-11-06 07:33:48
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 761 bytes
コンパイル時間 798 ms
コンパイル使用メモリ 73,468 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-16 13:56:41
合計ジャッジ時間 1,833 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 7 ms
4,380 KB
testcase_11 AC 7 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  int N;cin>>N;
  vector<string> v1(N);
  for(int i=0;i<N;++i){
    cin>>v1[i];
  }
  string T;
  while(1){
    sort(v1.begin(),v1.end());
    int ss1=v1[0].size();
    if(ss1==1){
      char a=v1[0][0];
      for(int i=0;i<v1.size();++i){
        int ss2=v1[i].size();
        char b=v1[i][0];
        if(a==b && ss2>1){
          string s3=v1[i];
          v1.erase(v1.begin()+i);
          v1.insert(v1.begin(),s3);
          break;
        }
      }
    }
    string s1=v1[0];
    string s2=s1.substr(0,1);
    T+=s2;
    v1[0].erase(v1[0].begin());
    if(v1[0].size()==0) v1.erase(v1.begin());
    if(v1.size()==0) break;
  }
  cout<<T<<endl;
}
0