結果

問題 No.54 Happy Hallowe'en
ユーザー PachicobuePachicobue
提出日時 2017-07-14 17:44:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,841 bytes
コンパイル時間 1,616 ms
コンパイル使用メモリ 169,324 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-16 19:49:51
合計ジャッジ時間 3,916 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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());
    prevcheck[house[0].v] = true;
    ll maxi = house[0].v;
    for (ll i = 1; i < N; i++) {
        ll maxi2 = maxi;
        for (ll j = max(0LL, maxi - house[i].v + 1); j <= min(house[i].t - 1, MAXIMUM - house[i].v); j++) {
            if (prevcheck[j]) {
                maxi2 = max(j + house[i].v, maxi2);
                check[j + house[i].v] = true;
            }
        }
        maxi = maxi2;
        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