結果

問題 No.54 Happy Hallowe'en
ユーザー PachicobuePachicobue
提出日時 2017-07-14 17:50:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 264 ms / 5,000 ms
コード長 1,652 bytes
コンパイル時間 1,766 ms
コンパイル使用メモリ 168,320 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 19:50:00
合計ジャッジ時間 3,955 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 70 ms
5,376 KB
testcase_05 AC 103 ms
5,376 KB
testcase_06 AC 137 ms
5,376 KB
testcase_07 AC 182 ms
5,376 KB
testcase_08 AC 220 ms
5,376 KB
testcase_09 AC 264 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 263 ms
5,376 KB
testcase_13 AC 262 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

constexpr int MAXV = 10000;
constexpr int MAXIMUM = 20000;
bool check[MAXIMUM + 1];
bool prevcheck[MAXIMUM + 1];

struct House {
    int v;
    int t;
    bool operator<(const House& h) const
    {
        return v + t < (h.v + h.t);
    }
};

int main()
{
    int N;
    cin >> N;
    vector<House> house(N);
    for (ll i = 0; i < N; i++) {
        cin >> house[i].v >> house[i].t;
    }
    prevcheck[0] = true;
    sort(house.begin(), house.end());
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j <= min(house[i].t - 1, MAXIMUM - house[i].v); j++) {
            if (prevcheck[j]) {
                check[j + house[i].v] = true;
            }
        }
        for (ll j = 0; j <= MAXIMUM; j++) {
            if (not prevcheck[j]) {
                prevcheck[j] = check[j];
            }
            check[j] = false;
        }
    }
    for (auto i = MAXIMUM; i >= 0; i--) {
        if (prevcheck[i]) {
            cout << i << endl;
            break;
        }
    }

    return 0;
}
0