Submission #928325
Source Code Expand
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main { static BufferedReader in; static PrintWriter out; static StringTokenizer tok; void solve() throws IOException { int N = ni(); int[] T = new int[N]; int[] A = new int[N]; for (int i=0; i<N; i++) { T[i] = ni(); A[i] = ni(); } long t = T[0]; long a = A[0]; for (int i=1; i<N; i++) { long x = (t%T[i]==0)? t/T[i] : (t/T[i] + 1); long y = (a%A[i]==0)? a/A[i] : (a/A[i] + 1); t = T[i] * Math.max(x, y); a = A[i] * Math.max(x, y); } out.println(t + a); } String ns() throws IOException { while (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine(), " "); } return tok.nextToken(); } int ni() throws IOException { return Integer.parseInt(ns()); } long nl() throws IOException { return Long.parseLong(ns()); } double nd() throws IOException { return Double.parseDouble(ns()); } String[] nsa(int n) throws IOException { String[] res = new String[n]; for (int i = 0; i < n; i++) { res[i] = ns(); } return res; } int[] nia(int n) throws IOException { int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = ni(); } return res; } long[] nla(int n) throws IOException { long[] res = new long[n]; for (int i = 0; i < n; i++) { res[i] = nl(); } return res; } public static void main(String[] args) throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); tok = new StringTokenizer(""); Main main = new Main(); main.solve(); out.close(); } }
Submission Info
Submission Time | |
---|---|
Task | C - AtCoDeer and Election Report |
User | CrazyBBB |
Language | Java8 (OpenJDK 1.8.0) |
Score | 300 |
Code Size | 2081 Byte |
Status | AC |
Exec Time | 121 ms |
Memory | 8908 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 96 ms | 8140 KB |
0_001.txt | AC | 95 ms | 8276 KB |
0_002.txt | AC | 95 ms | 8140 KB |
1_003.txt | AC | 95 ms | 8144 KB |
1_004.txt | AC | 114 ms | 8908 KB |
1_005.txt | AC | 112 ms | 8524 KB |
1_006.txt | AC | 111 ms | 8532 KB |
1_007.txt | AC | 113 ms | 8652 KB |
1_008.txt | AC | 98 ms | 8400 KB |
1_009.txt | AC | 97 ms | 8140 KB |
1_010.txt | AC | 96 ms | 8268 KB |
1_011.txt | AC | 97 ms | 8268 KB |
1_012.txt | AC | 99 ms | 8396 KB |
1_013.txt | AC | 121 ms | 8908 KB |
1_014.txt | AC | 106 ms | 8908 KB |