結果

問題 No.904 サメトロ
ユーザー iqueue02
提出日時 2019-10-24 20:31:26
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 12 ms / 1,000 ms
コード長 602 bytes
コンパイル時間 1,564 ms
コンパイル使用メモリ 169,676 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-18 03:42:23
合計ジャッジ時間 2,668 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n;
  cin >> n;
  vector<int> a(n-1), b(n-1);
  int sum_a = 0, sum_b = 0;
  rep(i,n-1){
    cin >> a[i] >> b[i];
    sum_a += a[i];
    sum_b += b[i];
  }
  int res = 0;
  for (int nb = 0; nb <= sum_a; nb++) {
    int na = sum_b + nb - sum_a;
    if (na < 0) continue;
    bool ok = true;
    rep(i,n-1){
      if (b[i] > sum_a + na - a[i]) ok = false;
    }
    if (ok) res++;
  }
  cout << res << endl;
  return 0;
}
0