結果
問題 | No.1141 田グリッド |
ユーザー | face4 |
提出日時 | 2020-08-10 11:17:38 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 787 ms / 2,000 ms |
コード長 | 2,293 bytes |
コンパイル時間 | 2,532 ms |
コンパイル使用メモリ | 78,864 KB |
実行使用メモリ | 64,956 KB |
最終ジャッジ日時 | 2024-04-16 06:33:40 |
合計ジャッジ時間 | 20,113 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
36,588 KB |
testcase_01 | AC | 51 ms
36,728 KB |
testcase_02 | AC | 51 ms
36,928 KB |
testcase_03 | AC | 53 ms
36,992 KB |
testcase_04 | AC | 61 ms
37,116 KB |
testcase_05 | AC | 52 ms
36,768 KB |
testcase_06 | AC | 51 ms
36,592 KB |
testcase_07 | AC | 52 ms
37,132 KB |
testcase_08 | AC | 120 ms
40,084 KB |
testcase_09 | AC | 102 ms
38,808 KB |
testcase_10 | AC | 110 ms
39,696 KB |
testcase_11 | AC | 129 ms
40,340 KB |
testcase_12 | AC | 118 ms
40,020 KB |
testcase_13 | AC | 731 ms
57,900 KB |
testcase_14 | AC | 787 ms
63,648 KB |
testcase_15 | AC | 719 ms
54,900 KB |
testcase_16 | AC | 714 ms
54,800 KB |
testcase_17 | AC | 728 ms
55,656 KB |
testcase_18 | AC | 719 ms
55,360 KB |
testcase_19 | AC | 726 ms
55,256 KB |
testcase_20 | AC | 713 ms
55,492 KB |
testcase_21 | AC | 730 ms
54,748 KB |
testcase_22 | AC | 725 ms
53,784 KB |
testcase_23 | AC | 750 ms
62,060 KB |
testcase_24 | AC | 710 ms
61,844 KB |
testcase_25 | AC | 697 ms
56,136 KB |
testcase_26 | AC | 741 ms
55,292 KB |
testcase_27 | AC | 739 ms
64,956 KB |
testcase_28 | AC | 683 ms
56,596 KB |
testcase_29 | AC | 712 ms
58,144 KB |
testcase_30 | AC | 728 ms
55,308 KB |
testcase_31 | AC | 703 ms
58,416 KB |
testcase_32 | AC | 720 ms
62,692 KB |
testcase_33 | AC | 709 ms
53,460 KB |
ソースコード
import java.io.*; import java.util.Arrays; public class Main { static long[][] cp(long[][] a){ int h = a.length, w = a[0].length; long[][] ret = new long[h][w]; for(int i = 0; i < h; i++){ ret[i] = Arrays.copyOf(a[i], a[i].length); } return ret; } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] line = br.readLine().split(" "); int h = Integer.parseInt(line[0]); int w = Integer.parseInt(line[1]); int mod = 1000000007; long a[][] = new long[h][w]; for(int i = 0; i < h; i++){ line = br.readLine().split(" "); for(int j = 0; j < w; j++){ a[i][j] = Integer.parseInt(line[j]); } } long l[][] = new long[h][w], r[][] = new long[h][w]; for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ if(j == 0){ l[i][j] = a[i][j]; r[i][w-1-j] = a[i][w-1-j]; }else{ l[i][j] = l[i][j-1]*a[i][j]%mod; r[i][w-1-j] = r[i][w-1-j+1]*a[i][w-1-j]%mod; } } } long ld[][] = cp(l), lu[][] = cp(l); long rd[][] = cp(r), ru[][] = cp(r); for(int i = 1; i < h; i++){ for(int j = 0; j < w; j++){ ld[i][j] = ld[i-1][j]*l[i][j]%mod; lu[h-1-i][j] = lu[h-1-i+1][j]*l[h-1-i][j]%mod; rd[i][w-1-j] = rd[i-1][w-1-j]*r[i][w-1-j]%mod; ru[h-1-i][w-1-j] = ru[h-1-i+1][w-1-j]*r[h-1-i][w-1-j]%mod; } } int q = Integer.parseInt(br.readLine()); while(q-- > 0){ line = br.readLine().split(" "); int x = Integer.parseInt(line[0])-1; int y = Integer.parseInt(line[1])-1; long ans = 1; if(x-1 >= 0 && y-1 >= 0) ans = ans*ld[x-1][y-1]%mod; if(x-1 >= 0 && y+1 < w) ans = ans*rd[x-1][y+1]%mod; if(x+1 < h && y-1 >= 0) ans = ans*lu[x+1][y-1]%mod; if(x+1 < h && y+1 < w) ans = ans*ru[x+1][y+1]%mod; System.out.println(ans); } } }