結果

問題 No.205 マージして辞書順最小
ユーザー ぷらぷら
提出日時 2024-02-24 20:07:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,699 ms / 5,000 ms
コード長 1,739 bytes
コンパイル時間 1,520 ms
コンパイル使用メモリ 142,384 KB
実行使用メモリ 162,012 KB
最終ジャッジ日時 2024-02-24 20:07:48
合計ジャッジ時間 14,769 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,516 KB
testcase_01 AC 3 ms
7,516 KB
testcase_02 AC 156 ms
28,380 KB
testcase_03 AC 167 ms
28,380 KB
testcase_04 AC 150 ms
27,740 KB
testcase_05 AC 131 ms
26,204 KB
testcase_06 AC 4 ms
7,516 KB
testcase_07 AC 1,668 ms
162,012 KB
testcase_08 AC 1,640 ms
162,012 KB
testcase_09 AC 1,664 ms
162,012 KB
testcase_10 AC 1,635 ms
162,012 KB
testcase_11 AC 1,644 ms
162,012 KB
testcase_12 AC 1,642 ms
162,012 KB
testcase_13 AC 1,699 ms
162,012 KB
testcase_14 AC 7 ms
8,028 KB
testcase_15 AC 4 ms
7,516 KB
testcase_16 AC 4 ms
7,516 KB
testcase_17 AC 4 ms
7,516 KB
testcase_18 AC 4 ms
7,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

string dp[2505][51];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<string>S(N);
    for(int i = 0; i < N; i++) {
        cin >> S[i];
    }
    string ans = S[0];
    for(int i = 1; i < N; i++) {
        for(int j = 0; j <= ans.size(); j++) {
            for(int k = 0; k <= S[i].size(); k++) {
                dp[j][k] = string(j+k,'z');
            }
        }
        for(int j = 0; j <= ans.size(); j++) {
            for(int k = 0; k <= S[i].size(); k++) {
                if(j == ans.size()) {
                    if(k == S[i].size()) {
                        break;
                    }
                    else {
                        dp[j][k+1] = min(dp[j][k+1],dp[j][k]+S[i][k]);
                    }
                }
                else if(k == S[i].size()) {
                    dp[j+1][k] = min(dp[j+1][k],dp[j][k]+ans[j]);
                }
                else {
                    dp[j+1][k] = min(dp[j+1][k],dp[j][k]+ans[j]);
                    dp[j][k+1] = min(dp[j][k+1],dp[j][k]+S[i][k]);
                }
            }
        }
        ans = dp[ans.size()][S[i].size()];
    }
    cout << ans << "\n";
}
0