結果

問題 No.904 サメトロ
ユーザー hipopo
提出日時 2020-01-12 18:05:51
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 10 ms / 1,000 ms
+ 858µs
コード長 639 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,240 ms
コンパイル使用メモリ 214,788 KB
実行使用メモリ 9,908 KB
最終ジャッジ日時 2026-10-25 04:43:20
合計ジャッジ時間 3,535 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge7_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<int> a(n - 1), b(n - 1);
    int sum_a = 0, sum_b = 0;
    for (int i = 0; i < n - 1; i++) {
        cin >> a.at(i) >> b.at(i);
        sum_a += a.at(i);
        sum_b += b.at(i);
    }

    int cnt = 0;
    int d = sum_a - sum_b;
    for (int a0 = 0; a0 <= sum_b; a0++) {
        int b0 = a0 + d;
        if (b0 < 0) continue;

        bool ok = true;
        for (int i = 0; i < n - 1; i++) {
            if (sum_b - b.at(i) + b0 < a.at(i)) ok = false;
        }
        if (ok) cnt++;
    }
    cout << cnt << endl;
}
0