結果

問題 No.205 マージして辞書順最小
ユーザー itezpaceitezpace
提出日時 2016-07-01 09:48:50
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,004 bytes
コンパイル時間 503 ms
コンパイル使用メモリ 65,996 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 05:02:09
合計ジャッジ時間 2,389 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(){
  int n;
  cin>>n;
  string s,t;
  vector<string> v;
  for(int i=0; i<n; ++i){
    cin>>s;
    v.push_back(s);
  }

  char c;
  c='{';
  int p;
  p=v.size();
  int f;
  f=0;

  while(1){
  vector<int> vp;
  f=0;
  for(int i=0; i<v.size(); ++i){
    char a;
    a=v[i][0];
    if(a<c && a!='\0'){
      c=a;
      p=i;
      vp.clear();
      vp.push_back(p);
    } else if(a==c && a!='\0'){
      p=i;
      vp.push_back(p);
    }
    if(v[i].size()==0) f++;
  }
  if(f==v.size()) break;

  t.push_back(c);

  if(vp.size()>1){
    char cp;
    cp='{';
    int pp;
    pp=vp.size();

    for(int i=0; i<vp.size(); ++i){
      int vvps;
      vvps=v[vp[i]].size();
      char ap;
      if(vvps>1){
        ap=v[vp[i]][1];
        if(ap<cp && ap!='\0'){
          cp=ap;
          pp=vp[i];
        }
      }
    }
    p=pp;
  }

  v[p].erase(v[p].begin());
  c='{';
  p=v.size();
  }

  cout<<t<<endl;
  return 0;
}
0