結果

問題 No.1141 田グリッド
ユーザー tnakao0123tnakao0123
提出日時 2020-08-06 15:32:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,992 bytes
コンパイル時間 915 ms
コンパイル使用メモリ 100,796 KB
実行使用メモリ 17,092 KB
最終ジャッジ日時 2023-10-19 22:18:12
合計ジャッジ時間 5,610 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 4 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 35 ms
6,272 KB
testcase_14 AC 65 ms
17,092 KB
testcase_15 AC 35 ms
5,932 KB
testcase_16 AC 34 ms
5,936 KB
testcase_17 AC 35 ms
6,000 KB
testcase_18 AC 33 ms
5,956 KB
testcase_19 AC 33 ms
5,940 KB
testcase_20 AC 33 ms
5,944 KB
testcase_21 AC 34 ms
5,864 KB
testcase_22 AC 34 ms
5,864 KB
testcase_23 AC 34 ms
5,864 KB
testcase_24 AC 33 ms
5,884 KB
testcase_25 AC 33 ms
5,584 KB
testcase_26 AC 33 ms
5,948 KB
testcase_27 AC 33 ms
6,008 KB
testcase_28 AC 33 ms
5,584 KB
testcase_29 AC 33 ms
5,844 KB
testcase_30 AC 34 ms
5,944 KB
testcase_31 AC 33 ms
5,844 KB
testcase_32 AC 33 ms
5,864 KB
testcase_33 AC 33 ms
5,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1141.cc:  No.1141 田グリッド - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_H = 100000;
const int MAX_W = 100000;
const int MOD = 1000000007;

/* typedef */

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

/* global variables */

/* subroutines */

void pmat(int h, int w, vvi &v) {
  for (int y = 0; y <= h; y++)
    for (int x = 0; x <= w; x++) {
      printf("%d ", v[y][x]);
      putchar(x < w ? ' ' : '\n');
    }
}

/* main */

int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  vvi as(h, vi(w, 1));

  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++) scanf("%d", &as[y][x]);

  vvi m00(h + 1, vi(w + 1, 1));
  vvi m01(h + 1, vi(w + 1, 1));
  vvi m10(h + 1, vi(w + 1, 1));
  vvi m11(h + 1, vi(w + 1, 1));
  
  for (int y0 = 0, y1 = h - 1; y0 < h; y0++, y1--) {
    int p00 = 1, p01 = 1, p10 = 1, p11 = 1;
    for (int x0 = 0, x1 = w - 1; x0 < w; x0++, x1--) {
      p00 = (ll)p00 * as[y0][x0] % MOD;
      p01 = (ll)p01 * as[y0][x1] % MOD;
      p10 = (ll)p10 * as[y1][x0] % MOD;
      p11 = (ll)p11 * as[y1][x1] % MOD;
      m00[y0 + 1][x0 + 1] = (ll)m00[y0][x0 + 1] * p00 % MOD;
      m01[y0 + 1][x1] = (ll)m01[y0][x1] * p01 % MOD;
      m10[y1][x0 + 1] = (ll)m10[y1 + 1][x0 + 1] * p10 % MOD;
      m11[y1][x1] = (ll)m11[y1 + 1][x1] * p11 % MOD;
    }
  }
  //pmat(h, w, m00); pmat(h, w, m01); pmat(h, w, m10); pmat(h, w, m11);

  int q;
  scanf("%d", &q);

  while (q--) {
    int r, c;
    scanf("%d%d", &r, &c);
    r--, c--;

    int p =
      (ll)m00[r][c] * m01[r][c + 1] % MOD *
      m10[r + 1][c] % MOD * m11[r + 1][c + 1] % MOD;
    printf("%d\n", p);
  }
  return 0;
}
0