Submission #1306084
Source Code Expand
import java.io.*; import java.math.*; import java.util.*; public class Main { private static boolean debug = false; private static boolean elapsed = false; private static PrintWriter _out = new PrintWriter(System.out); private static PrintWriter _err = new PrintWriter(System.err); private void solve(Scanner sc) { int N = sc.nextInt(); long[] A = new long[N]; long[] B = new long[N]; long[] r = new long[N]; for (int i = 0; i < N; ++i) { A[i] = sc.nextLong(); B[i] = sc.nextLong(); r[i] = B[i] - (A[i] % B[i]); } long ans = 0; for (int i = N - 1; i >= 0; --i) { long ct = r[i] - ans; while (ct < 0) { ct += B[i]; } ct = ct % B[i]; ans += ct; } _out.println(ans); } private static BigInteger C(long n, long r) { BigInteger res = BigInteger.ONE; for (long i = n; i > n - r; --i) { res = res.multiply(BigInteger.valueOf(i)); } for (long i = r; i > 1; --i) { res = res.divide(BigInteger.valueOf(i)); } return res; } private static BigInteger P(long n, long r) { BigInteger res = BigInteger.ONE; for (long i = n; i > n - r; --i) { res = res.multiply(BigInteger.valueOf(i)); } return res; } /* * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9 * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18 */ public static void main(String[] args) { long S = System.currentTimeMillis(); Scanner sc = new Scanner(System.in); new Main().solve(sc); _out.flush(); long G = System.currentTimeMillis(); if (elapsed) { _err.println((G - S) + "ms"); } _err.flush(); } }
Submission Info
Submission Time | |
---|---|
Task | A - Multiple Array |
User | hhelibex |
Language | Java8 (OpenJDK 1.8.0) |
Score | 0 |
Code Size | 1972 Byte |
Status | TLE |
Exec Time | 2109 ms |
Memory | 89304 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 300 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, s1.txt, s2.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | TLE | 2105 ms | 65848 KB |
02.txt | TLE | 2109 ms | 64924 KB |
03.txt | TLE | 2109 ms | 67180 KB |
04.txt | TLE | 2109 ms | 64304 KB |
05.txt | TLE | 2109 ms | 67476 KB |
06.txt | TLE | 2105 ms | 61644 KB |
07.txt | AC | 549 ms | 83216 KB |
08.txt | AC | 1382 ms | 81324 KB |
09.txt | AC | 518 ms | 89304 KB |
10.txt | TLE | 2109 ms | 84236 KB |
11.txt | AC | 541 ms | 66200 KB |
12.txt | AC | 528 ms | 84272 KB |
13.txt | TLE | 2109 ms | 64240 KB |
14.txt | AC | 575 ms | 65036 KB |
15.txt | AC | 91 ms | 19540 KB |
16.txt | AC | 97 ms | 18636 KB |
s1.txt | AC | 93 ms | 17748 KB |
s2.txt | AC | 95 ms | 18772 KB |