結果
問題 | No.904 サメトロ |
ユーザー |
![]() |
提出日時 | 2019-12-05 19:18:07 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 194 ms / 1,000 ms |
コード長 | 1,981 bytes |
コンパイル時間 | 4,020 ms |
コンパイル使用メモリ | 78,984 KB |
実行使用メモリ | 41,508 KB |
最終ジャッジ日時 | 2024-12-21 15:03:42 |
合計ジャッジ時間 | 11,133 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
import java.io.InputStream; import java.io.PrintWriter; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Scanner; import java.util.Set; import java.util.TreeSet; import static java.util.Comparator.*; public class Main { public static void main(String[] args) { PrintWriter out = new PrintWriter(System.out); Solver solver = new Solver(System.in, out); solver.solve(); out.close(); } } class Solver { Scanner sc; PrintWriter out; public Solver(InputStream in, PrintWriter out) { sc = new Scanner(in); this.out = out; } // ================================================================== public void solve() { int N = Integer.parseInt(sc.next()); int[] A = new int[N]; int[] B = new int[N]; int sumA = 0, sumB = 0; for (int i = 0; i < N -1 ; i++) { A[i] = Integer.parseInt(sc.next()); B[i] = Integer.parseInt(sc.next()); sumA += A[i]; sumB += B[i]; } int a1, b1, sa, ans = 0; boolean flg; if(sumA >= sumB) { sa = sumA - sumB; a1 = 0; for (; a1 <= sumB; a1++) { b1 = a1 + sa; flg = true; for (int j = 0; j < N - 1; j++) { if(A[j] > b1 + sumB - B[j] || B[j] > a1 + sumA - A[j]) { flg = false; break; } } if(flg) ans++; } } else { sa = sumB - sumA; b1 = 0; for (; b1 <= sumA; b1++) { a1 = b1 + sa; flg = true; for (int j = 0; j < N - 1; j++) { if(A[j] > b1 + sumB - B[j] || B[j] > a1 + sumA - A[j]) { flg = false; break; } } if(flg) ans++; } } out.println(ans); } // ================================================================== } class PP{ public int key, val; public PP(int key, int val) { this.key = key; this.val = val; } public int getKey() { return key; } public int getVal() { return val; } }