結果
問題 | No.989 N×Mマス計算(K以上) |
ユーザー | Tatsuyaaaa |
提出日時 | 2020-02-14 22:13:04 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 504 ms / 2,000 ms |
コード長 | 2,988 bytes |
コンパイル時間 | 2,678 ms |
コンパイル使用メモリ | 91,032 KB |
実行使用メモリ | 50,236 KB |
最終ジャッジ日時 | 2024-04-16 02:24:25 |
合計ジャッジ時間 | 8,078 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 67 ms
37,636 KB |
testcase_01 | AC | 65 ms
37,560 KB |
testcase_02 | AC | 70 ms
37,656 KB |
testcase_03 | AC | 68 ms
37,372 KB |
testcase_04 | AC | 67 ms
37,132 KB |
testcase_05 | AC | 68 ms
37,660 KB |
testcase_06 | AC | 69 ms
37,456 KB |
testcase_07 | AC | 66 ms
37,480 KB |
testcase_08 | AC | 70 ms
37,148 KB |
testcase_09 | AC | 70 ms
37,680 KB |
testcase_10 | AC | 414 ms
49,636 KB |
testcase_11 | AC | 386 ms
48,992 KB |
testcase_12 | AC | 430 ms
50,236 KB |
testcase_13 | AC | 342 ms
46,732 KB |
testcase_14 | AC | 504 ms
49,612 KB |
testcase_15 | AC | 274 ms
47,032 KB |
testcase_16 | AC | 359 ms
47,928 KB |
testcase_17 | AC | 323 ms
46,164 KB |
testcase_18 | AC | 287 ms
47,764 KB |
testcase_19 | AC | 431 ms
49,432 KB |
ソースコード
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; import java.util.*; public class Main { public static boolean isOK(int index, long key, long[] a, char op) { if (a[index] >= key) return true; else return false; } public static int binary_search(long key, long[] a, char op) { int left = -1; int right = a.length; while (right - left > 1) { int mid = left + (right - left) / 2; if (isOK(mid, key, a, op)) right = mid; else left = mid; } return right; } public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); int N = in.nextInt(); int M = in.nextInt(); int K = in.nextInt(); String S = in.next(); Long[] B = new Long[M]; Long[] A = new Long[N]; // long B_sum = 0L; // long A_sum = 0L; for (int i=0;i<M;i++) { B[i] = in.nextLong(); // B_sum += B[i]; } for (int i=0;i<N;i++) { A[i] = in.nextLong(); // A_sum += A[i]; } Arrays.sort(B); long ans = 0L; char op = S.charAt(0); for (int i=0;i<N;i++) { long tmp = 0; if (op=='+') tmp = K-A[i]; if (op=='*') tmp = (K+A[i]-1)/A[i]; // ans += binary_search(tmp, B, op); int index = ~Arrays.binarySearch(B, tmp, (o1, o2)->o1>=o2?1:-1); ans += M-index; } out.println(ans); // B_sum%=K; // A_sum%=K; // if (S.charAt(0)=='+') { // out.println((N*B_sum%K+M*A_sum%K)%K); // } else { // S.charAt(0)=='*' // long ans = 0L; // out.println(B_sum*A_sum%K); // } out.close(); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }