結果
問題 | No.1141 田グリッド |
ユーザー | Apass |
提出日時 | 2020-08-01 00:36:32 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,268 bytes |
コンパイル時間 | 4,647 ms |
コンパイル使用メモリ | 74,940 KB |
実行使用メモリ | 54,148 KB |
最終ジャッジ日時 | 2023-09-21 04:21:55 |
合計ジャッジ時間 | 16,662 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
33,620 KB |
testcase_01 | AC | 41 ms
33,644 KB |
testcase_02 | AC | 40 ms
33,952 KB |
testcase_03 | AC | 42 ms
33,628 KB |
testcase_04 | AC | 40 ms
33,492 KB |
testcase_05 | AC | 40 ms
33,528 KB |
testcase_06 | AC | 39 ms
33,892 KB |
testcase_07 | AC | 39 ms
33,540 KB |
testcase_08 | AC | 102 ms
36,516 KB |
testcase_09 | AC | 84 ms
36,196 KB |
testcase_10 | AC | 105 ms
36,452 KB |
testcase_11 | AC | 97 ms
36,336 KB |
testcase_12 | AC | 106 ms
36,608 KB |
testcase_13 | AC | 482 ms
54,148 KB |
testcase_14 | AC | 418 ms
48,056 KB |
testcase_15 | AC | 410 ms
43,808 KB |
testcase_16 | AC | 403 ms
43,996 KB |
testcase_17 | AC | 407 ms
43,920 KB |
testcase_18 | AC | 398 ms
44,380 KB |
testcase_19 | AC | 397 ms
44,424 KB |
testcase_20 | AC | 401 ms
44,160 KB |
testcase_21 | AC | 413 ms
43,680 KB |
testcase_22 | AC | 406 ms
43,640 KB |
testcase_23 | AC | 400 ms
45,056 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
ソースコード
import java.io.*; import java.util.*; // https://yukicoder.me/problems/no/1141 public class RiceFieldGrid { static final int MOD = 1000000007; // 10**9 + 7 private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); private static final PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); private static StringTokenizer st; private static int readInt() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return Integer.parseInt(st.nextToken()); } public static void main(String[] args) throws IOException { solve(); pw.close(); } private static void solve() throws IOException { int H = readInt(); int W = readInt(); long[][] g = new long[H][W]; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { g[i][j] = readInt(); } } long[] rowProduct = new long[H]; long allProduct = 1; for (int i = 0; i < H; i++) { long prod = 1; for (int j = 0; j < W; j++) { prod = prod * g[i][j] % MOD; } rowProduct[i] = prod; allProduct = allProduct * prod % MOD; } long[] columnProduct = new long[W]; for (int j = 0; j < W; j++) { long prod = 1; for (int i = 0; i < H; i++) { prod = prod * g[i][j] % MOD; } columnProduct[j] = prod; } int Q = readInt(); for (int i = 0; i < Q; i++) { int r = readInt() - 1; int c = readInt() - 1; pw.println(allProduct * inverse(rowProduct[r]) % MOD * inverse(columnProduct[c]) % MOD * g[r][c] % MOD); } } static long inverse(long num) { // raise MOD to p-2 power. long base = num; long inverse = 1; int exp = MOD - 2; while (exp > 0) { if (exp % 2 == 1) inverse = inverse * base % MOD; base = base * base % MOD; exp /= 2; } return inverse; } }