結果

問題 No.1141 田グリッド
ユーザー kk
提出日時 2020-09-05 04:51:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,061 bytes
コンパイル時間 2,420 ms
コンパイル使用メモリ 205,580 KB
実行使用メモリ 6,336 KB
最終ジャッジ日時 2023-08-18 04:50:11
合計ジャッジ時間 8,474 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 103 ms
4,380 KB
testcase_14 AC 112 ms
6,336 KB
testcase_15 AC 102 ms
4,380 KB
testcase_16 AC 101 ms
4,376 KB
testcase_17 AC 101 ms
4,380 KB
testcase_18 AC 101 ms
4,380 KB
testcase_19 AC 102 ms
4,376 KB
testcase_20 AC 104 ms
4,380 KB
testcase_21 AC 102 ms
4,376 KB
testcase_22 AC 101 ms
4,380 KB
testcase_23 AC 102 ms
4,376 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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

const long long MOD = 1e9 + 7;

long long modpow(long long x, long long p, long long mod) {
  long long ret = 1;
  while (p) {
    if (p & 1)
      ret = ret * x % mod;
    x = x * x % mod;
    p >>= 1;
  }
  return ret;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int h, w;
  cin >> h >> w;
  vector<vector<int> > a(h, vector<int>(w));

  long long sum = 1;
  REP (i, h) REP (j, w) {
    cin >> a[i][j];
    sum = sum * a[i][j] % MOD;
  }

  vector<long long> hsum(h), wsum(w);
  REP (i, h) {
    hsum[i] = 1;
    REP (j, w) hsum[i] = hsum[i] * a[i][j] % MOD;
  }
  REP (j, w) {
    wsum[j] = 1;
    REP (i, h) wsum[j] = wsum[j] * a[i][j] % MOD;
  }
  
  int q;
  cin >> q;
  while (q--) {
    int r, c;
    cin >> r >> c;
    --r, --c;
    long long ret = a[r][c];
    ret = ret * sum % MOD;
    ret = ret * modpow(hsum[r], MOD-2, MOD) % MOD;
    ret = ret * modpow(wsum[c], MOD-2, MOD) % MOD;
    cout << ret << endl;
  }
    
  return 0;
}
0