結果
| 問題 |
No.904 サメトロ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-10-11 22:03:41 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 29 ms / 1,000 ms |
| コード長 | 798 bytes |
| コンパイル時間 | 1,343 ms |
| コンパイル使用メモリ | 168,000 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-25 07:31:14 |
| 合計ジャッジ時間 | 2,289 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
int as = 0, bs = 0;
vector<int> a(n), b(n);
for (int i = 1; i < n; i++) {
cin >> a[i] >> b[i];
as += a[i];
bs += b[i];
}
int minv = max(bs - as, 0);
int maxv = bs;
int ans = 0;
for (int a1 = minv; a1 <= maxv; a1++) {
a[0] = a1;
int aa = as + a1;
int bb = aa;
b[0] = bb - bs;
if (b[0] < 0) continue;
bool f = true;
for (int i = 0; i < n; i++) {
if (a[i] <= bb - b[i] && b[i] <= aa - a[i]) continue;
f = false;
break;
}
ans += f;
}
cout << ans << "\n";
return 0;
}