結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 6 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 6 ms
5,376 KB
testcase_13 AC 7 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 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;
int check[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;
    }
    check[0] = 1;
    sort(house.begin(), house.end());
    check[house[0].v] = 2;
    int maxi = house[0].v;
    for (ll i = 1; i < N; i++) {
        ll maxi2 = maxi;
        for (ll j = max(0, maxi - house[i].v + 1); j <= min(house[i].t - 1, MAXIMUM - house[i].v); j++) {
            if (check[j] > 0 and check[j] <= i + 1) {
                maxi2 = max(j + house[i].v, maxi2);
                check[j + house[i].v] = i + 2;
            }
        }
        maxi = maxi2;
    }
    for (auto i = MAXIMUM; i >= 0; i--) {
        if (check[i] > 0) {
            cout << i << endl;
            break;
        }
    }

    return 0;
}
0