結果

問題 No.1141 田グリッド
ユーザー SSRSSSRS
提出日時 2020-07-31 21:34:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 1,756 bytes
コンパイル時間 1,969 ms
コンパイル使用メモリ 173,428 KB
実行使用メモリ 20,748 KB
最終ジャッジ日時 2023-09-20 22:01:02
合計ジャッジ時間 6,560 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 143 ms
10,940 KB
testcase_14 AC 170 ms
20,748 KB
testcase_15 AC 139 ms
7,580 KB
testcase_16 AC 138 ms
7,420 KB
testcase_17 AC 138 ms
7,496 KB
testcase_18 AC 137 ms
7,516 KB
testcase_19 AC 136 ms
7,436 KB
testcase_20 AC 139 ms
7,472 KB
testcase_21 AC 139 ms
7,444 KB
testcase_22 AC 138 ms
7,588 KB
testcase_23 AC 138 ms
7,396 KB
testcase_24 AC 138 ms
7,380 KB
testcase_25 AC 138 ms
7,284 KB
testcase_26 AC 139 ms
7,556 KB
testcase_27 AC 140 ms
7,608 KB
testcase_28 AC 138 ms
7,284 KB
testcase_29 AC 136 ms
7,364 KB
testcase_30 AC 139 ms
7,472 KB
testcase_31 AC 141 ms
7,564 KB
testcase_32 AC 137 ms
7,384 KB
testcase_33 AC 137 ms
7,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<long long>> A(H + 2, vector<long long>(W + 2, 1));
  for (int i = 1; i <= H; i++){
    for (int j = 1; j <= W; j++){
      cin >> A[i][j];
    }
  }
  vector<vector<long long>> P1 = A, P2 = A, P3 = A, P4 = A;
  for (int i = 1; i <= H + 1; i++){
    for (int j = 1; j <= W + 1; j++){
      P1[i][j] *= P1[i][j - 1];
      P1[i][j] %= MOD;
    }
  }
  for (int j = 1; j <= W + 1; j++){
    for (int i = 1; i <= H + 1; i++){
      P1[i][j] *= P1[i - 1][j];
      P1[i][j] %= MOD;
    }
  }
  for (int i = 1; i <= H + 1; i++){
    for (int j = W; j >= 0; j--){
      P2[i][j] *= P2[i][j + 1];
      P2[i][j] %= MOD;
    }
  }
  for (int j = 0; j <= W; j++){
    for (int i = 1; i <= H + 1; i++){
      P2[i][j] *= P2[i - 1][j];
      P2[i][j] %= MOD;
    }
  }
  for (int i = 1; i <= H + 1; i++){
    for (int j = 1; j <= W + 1; j++){
      P3[i][j] *= P3[i][j - 1];
      P3[i][j] %= MOD;
    }
  }
  for (int j = 1; j <= W + 1; j++){
    for (int i = H; i >= 0; i--){
      P3[i][j] *= P3[i + 1][j];
      P3[i][j] %= MOD;
    }
  }
  for (int i = 1; i <= H + 1; i++){
    for (int j = W; j >= 0; j--){
      P4[i][j] *= P4[i][j + 1];
      P4[i][j] %= MOD;
    }
  }
  for (int j = 1; j <= W + 1; j++){
    for (int i = H; i >= 0; i--){
      P4[i][j] *= P4[i + 1][j];
      P4[i][j] %= MOD;
    }
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++){
    int r, c;
    cin >> r >> c;
    long long ans = 1;
    ans *= P1[r - 1][c - 1];
    ans %= MOD;
    ans *= P2[r - 1][c + 1];
    ans %= MOD;
    ans *= P3[r + 1][c - 1];
    ans %= MOD;
    ans *= P4[r + 1][c + 1];
    ans %= MOD;
    cout << ans << endl;
  }
}
0