結果
| 問題 |
No.205 マージして辞書順最小
|
| コンテスト | |
| ユーザー |
EmKjp
|
| 提出日時 | 2015-03-25 01:25:40 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,725 bytes |
| コンパイル時間 | 1,556 ms |
| コンパイル使用メモリ | 89,204 KB |
| 実行使用メモリ | 8,576 KB |
| 最終ジャッジ日時 | 2024-06-29 00:42:28 |
| 合計ジャッジ時間 | 1,592 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 2 |
| other | AC * 3 WA * 12 |
ソースコード
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<numeric>
#include<functional>
#include<complex>
#include<cassert>
using namespace std;
#define BET(a,b,c) ((a)<=(b)&&(b)<(c))
#define FOR(i,n) for(int i=0,i##_end=(int(n));i<i##_end;i++)
#define SZ(x) (int)(x.size())
#define ALL(x) (x).begin(),(x).end()
#define MP make_pair
#define FOR_EACH(it,v) for(__typeof(v.begin()) it=v.begin(),it_end=v.end() ; it != it_end ; it++)
typedef vector<int> VI;
typedef vector<VI> VVI;
string memo[2510][55];
string dfs(const string&s1, const string&s2, int p1, int p2){
string& ret = memo[p1][p2];
if(ret != "") return ret;
if(p1 < SZ(s1) && p2 < SZ(s2)){
if(s1[p1] < s2[p2]){
ret = s1[p1] + dfs(s1, s2, p1+1, p2);
}
if(s1[p1] > s2[p2]){
ret = s2[p2] + dfs(s1, s2, p1, p2+1);
}
if(s1[p1] != s2[p2]){
string a = s1[p1] + dfs(s1, s2, p1+1, p2);
string b = s2[p2] + dfs(s1, s2, p1, p2+1);
ret = min(a, b);
}
}else if(p1 < SZ(s1)){
ret = s1[p1] + dfs(s1, s2, p1+1, p2);
}else if(p2 < SZ(s2)){
ret = s2[p2] + dfs(s1, s2, p1, p2+1);
}
return ret;
}
string merge(string s1, string s2){
FOR(i,SZ(s1)+1) FOR(j,SZ(s2)+1) {
memo[i][j] = "";
}
return dfs(s1, s2, 0, 0);
}
int main()
{
int n;
cin>>n;
assert(1 <= n && n <= 50);
vector<string> s(n);
FOR(i,n) {
cin>>s[i];
}
string ans = s[0];
for(int i=1;i<n;i++) ans = merge(ans, s[i]);
cout<<ans<<endl;
return 0;
}
EmKjp