結果

問題 No.1141 田グリッド
ユーザー itohdakitohdak
提出日時 2020-08-01 00:04:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,602 bytes
コンパイル時間 2,555 ms
コンパイル使用メモリ 209,796 KB
実行使用メモリ 23,384 KB
最終ジャッジ日時 2023-09-21 03:47:38
合計ジャッジ時間 5,185 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 39 ms
12,288 KB
testcase_14 AC 71 ms
23,384 KB
testcase_15 AC 38 ms
7,960 KB
testcase_16 AC 38 ms
7,712 KB
testcase_17 AC 37 ms
7,968 KB
testcase_18 AC 36 ms
7,968 KB
testcase_19 AC 37 ms
7,720 KB
testcase_20 AC 37 ms
8,080 KB
testcase_21 AC 38 ms
7,752 KB
testcase_22 AC 36 ms
7,716 KB
testcase_23 AC 36 ms
7,756 KB
testcase_24 AC 37 ms
7,796 KB
testcase_25 AC 36 ms
7,984 KB
testcase_26 AC 37 ms
8,060 KB
testcase_27 AC 36 ms
7,964 KB
testcase_28 AC 35 ms
7,984 KB
testcase_29 AC 36 ms
7,716 KB
testcase_30 AC 36 ms
8,044 KB
testcase_31 AC 36 ms
7,716 KB
testcase_32 AC 35 ms
7,812 KB
testcase_33 AC 36 ms
7,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

ll modinv(ll a, ll m=mod) {
  ll b = m, u = 1, v = 0;
  while(b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if(u < 0) u += m;
  return u;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  vector<vector<ll>> A(h, vector<ll>(w));
  rep(i, h) rep(j, w) cin >> A[i][j];
  vector<vector<vector<ll>>> sum(4, vector<vector<ll>>(h+2, vector<ll>(w+2, 1)));
  rep(i, h) rep(j, w) sum[0][i+1][j+1] = sum[0][i+1][j] * A[i][j] % mod;
  rep(j, w) rep(i, h) (sum[0][i+1][j+1] *= sum[0][i][j+1]) %= mod;
  rep(i, h) rrep(j, w) sum[1][i+1][j+1] = sum[1][i+1][j+2] * A[i][j] % mod;
  rep(j, w) rep(i, h) (sum[1][i+1][j+1] *= sum[1][i][j+1]) %= mod;
  rep(i, h) rep(j, w) sum[2][i+1][j+1] = sum[2][i+1][j] * A[i][j] % mod;
  rep(j, w) rrep(i, h) (sum[2][i+1][j+1] *= sum[2][i+2][j+1]) %= mod;
  rep(i, h) rrep(j, w) sum[3][i+1][j+1] = sum[3][i+1][j+2] * A[i][j] % mod;
  rep(j, w) rrep(i, h) (sum[3][i+1][j+1] *= sum[3][i+2][j+1]) %= mod;
  int q; cin >> q;
  while(q--) {
    int r, c; cin >> r >> c;
    r--; c--;
    cout << sum[0][r][c] * sum[1][r][c+2] % mod * sum[2][r+2][c] % mod * sum[3][r+2][c+2] % mod << "\n";
  }
  return 0;
}
0