提出 #35308438


ソースコード 拡げる

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <cstring>
#include <set>

using namespace std;

int main() {
    int n, s;
    cin >> n >> s;
    vector<int> as(n), bs(n);
    for (int i = 0; i < n; i++) {cin >> as[i] >> bs[i];}
    vector<int> memo(s+1, -1);
    vector<string> history(s+1, "");
    memo[0] = 0;
    for (int i = 0; i < n; i++) {
        vector<string> next_history(s+1, "");    
        vector<int> next_memo(s+1, -1);
        for (int j = 0; j < memo.size(); j++) {
            if (memo[j] == -1) { continue; }
            {
                int next_h = j + as[i];
                if (next_h <= s) {
                    next_memo[next_h] = 0;
                    next_history[next_h] = history[j] + "H";
                }
            }
            {
                int next_t = j + bs[i];
                if (next_t <= s) {
                    next_memo[next_t] = 0;
                    next_history[next_t] = history[j] + "T";
                }
            }
        }
        /*
        for (int j = 0; j < next_history.size(); j++) {
            cout << j << "= " << next_history[j] << endl;
        }
        cout << "------" << endl;
        */
        memo = next_memo;
        history = next_history;
    }
    if (history[s].size() == n) {
        cout << "Yes" << endl;
        cout << history[s] << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

提出情報

提出日時
問題 D - Flip and Adjust
ユーザ tomoya
言語 C++ (Clang 10.0.0)
得点 400
コード長 1511 Byte
結果 AC
実行時間 39 ms
メモリ 4656 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 2
AC × 26
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, handmade_00.txt, handmade_01.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 10 ms 3068 KiB
example_01.txt AC 3 ms 2988 KiB
handmade_00.txt AC 15 ms 3400 KiB
handmade_01.txt AC 34 ms 4304 KiB
test_00.txt AC 18 ms 3764 KiB
test_01.txt AC 2 ms 3068 KiB
test_02.txt AC 7 ms 3224 KiB
test_03.txt AC 16 ms 3472 KiB
test_04.txt AC 2 ms 3044 KiB
test_05.txt AC 14 ms 3448 KiB
test_06.txt AC 20 ms 3808 KiB
test_07.txt AC 21 ms 3856 KiB
test_08.txt AC 13 ms 3444 KiB
test_09.txt AC 14 ms 3540 KiB
test_10.txt AC 11 ms 3268 KiB
test_11.txt AC 7 ms 3156 KiB
test_12.txt AC 14 ms 3532 KiB
test_13.txt AC 3 ms 3056 KiB
test_14.txt AC 13 ms 3328 KiB
test_15.txt AC 27 ms 4084 KiB
test_16.txt AC 2 ms 3044 KiB
test_17.txt AC 5 ms 3008 KiB
test_18.txt AC 25 ms 4180 KiB
test_19.txt AC 34 ms 4284 KiB
test_20.txt AC 14 ms 3596 KiB
test_21.txt AC 39 ms 4656 KiB