結果

問題 No.1141 田グリッド
ユーザー face4face4
提出日時 2020-08-10 11:15:54
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,289 bytes
コンパイル時間 2,413 ms
コンパイル使用メモリ 78,528 KB
実行使用メモリ 64,716 KB
最終ジャッジ日時 2024-04-16 06:28:07
合計ジャッジ時間 20,935 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
36,768 KB
testcase_01 AC 50 ms
36,896 KB
testcase_02 AC 52 ms
36,860 KB
testcase_03 AC 53 ms
37,012 KB
testcase_04 AC 51 ms
37,080 KB
testcase_05 AC 52 ms
36,804 KB
testcase_06 AC 51 ms
36,920 KB
testcase_07 AC 53 ms
36,484 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 702 ms
57,840 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 712 ms
55,012 KB
testcase_19 AC 736 ms
55,236 KB
testcase_20 AC 713 ms
54,980 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

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];
            }
        }
        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);
        }
    }
}
0