結果
問題 |
No.989 N×Mマス計算(K以上)
|
ユーザー |
![]() |
提出日時 | 2020-03-05 10:16:48 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 998 ms / 2,000 ms |
コード長 | 2,153 bytes |
コンパイル時間 | 2,293 ms |
コンパイル使用メモリ | 79,340 KB |
実行使用メモリ | 63,808 KB |
最終ジャッジ日時 | 2024-10-14 00:50:51 |
合計ジャッジ時間 | 11,659 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; import java.util.Comparator; import java.util.ArrayList; /** * Built using CHelper plug-in * Actual solution is at the top * * @author silviase */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); nmCalc solver = new nmCalc(); solver.solve(1, in, out); out.close(); } static class nmCalc { public void solve(int testNumber, Scanner in, PrintWriter out) { // 愚直だと死んでしまうので二分探索かしゃくとりだけど尺取り法でよさそう…? // どっちも出してどっちもACすればええやん!人生は冒険や! int n = in.nextInt(); int m = in.nextInt(); int k = in.nextInt(); long ans = 0; String op = in.next(); ArrayList<Long> min2max = new ArrayList<>(); ArrayList<Long> max2min = new ArrayList<>(); for (int i = 0; i < m; i++) { min2max.add(in.nextLong()); } for (int i = 0; i < n; i++) { max2min.add(in.nextLong()); } min2max.sort(Comparator.naturalOrder()); max2min.sort(Comparator.naturalOrder()); for (Long l : min2max) { int ng = -1; int ok = max2min.size(); while (Math.abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if ((op.charAt(0) == '+' && l + max2min.get(mid) >= k) || (op.charAt(0) == '*' && l * max2min.get(mid) >= k)) { ok = mid; } else { ng = mid; } } ans += (n - ok); } out.println(ans); } } }