Submission #1306069


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] = A[i] % B[i];
        }

        long ans = 0;
        for (int i = N - 1; i >= 0; --i) {
            if (r[i] > 0) {
                long ct = B[i] - r[i];
                ans += ct;
                for (int j = 0; j <= i; ++j) {
                    r[j] = (r[j] + ct) % B[j];
                }
            }
        }
        _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 2028 Byte
Status TLE
Exec Time 2109 ms
Memory 89468 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
AC × 2
AC × 9
TLE × 9
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 2109 ms 87500 KB
02.txt TLE 2105 ms 67068 KB
03.txt TLE 2109 ms 89468 KB
04.txt TLE 2109 ms 63140 KB
05.txt TLE 2105 ms 66728 KB
06.txt TLE 2109 ms 63768 KB
07.txt AC 534 ms 62048 KB
08.txt TLE 2105 ms 64160 KB
09.txt AC 546 ms 85020 KB
10.txt TLE 2108 ms 66688 KB
11.txt AC 526 ms 63888 KB
12.txt AC 504 ms 66620 KB
13.txt TLE 2109 ms 77356 KB
14.txt AC 578 ms 64396 KB
15.txt AC 91 ms 21204 KB
16.txt AC 96 ms 19540 KB
s1.txt AC 92 ms 20820 KB
s2.txt AC 92 ms 18644 KB