結果

問題 No.1141 田グリッド
ユーザー motmot
提出日時 2020-08-01 01:56:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 189 ms / 2,000 ms
コード長 1,852 bytes
コンパイル時間 1,009 ms
コンパイル使用メモリ 85,560 KB
実行使用メモリ 4,724 KB
最終ジャッジ日時 2023-09-21 06:13:19
合計ジャッジ時間 6,093 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 4 ms
4,384 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 4 ms
4,384 KB
testcase_13 AC 189 ms
4,704 KB
testcase_14 AC 189 ms
4,724 KB
testcase_15 AC 184 ms
4,380 KB
testcase_16 AC 184 ms
4,408 KB
testcase_17 AC 184 ms
4,380 KB
testcase_18 AC 126 ms
4,376 KB
testcase_19 AC 126 ms
4,380 KB
testcase_20 AC 126 ms
4,384 KB
testcase_21 AC 184 ms
4,380 KB
testcase_22 AC 187 ms
4,384 KB
testcase_23 AC 185 ms
4,384 KB
testcase_24 AC 125 ms
4,376 KB
testcase_25 AC 127 ms
4,380 KB
testcase_26 AC 127 ms
4,384 KB
testcase_27 AC 125 ms
4,376 KB
testcase_28 AC 130 ms
4,380 KB
testcase_29 AC 128 ms
4,380 KB
testcase_30 AC 126 ms
4,396 KB
testcase_31 AC 125 ms
4,432 KB
testcase_32 AC 124 ms
4,376 KB
testcase_33 AC 124 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int H, W;
  cin>>H>>W;
  ll A[H][W];
  ll sumA = 1;
  ll tate[H], yoko[W];
  int tatezero[H], yokozero[W];
  int zeronum = 0;
  for(int i=0;i<H;++i) {
    tate[i] = 1;
    tatezero[i] = 0;
  }
  for(int i=0;i<W;++i) {
    yoko[i] = 1;
    yokozero[i] = 0;
  }
  for(int i=0;i<H;++i) {
    for(int j=0;j<W;++j) {
      cin>>A[i][j];
      if(A[i][j]==0) {
        zeronum++;
        tatezero[i]++;
        yokozero[j]++;
        continue;
      }
      sumA *= A[i][j];
      sumA %= mod;
      tate[i] *= A[i][j];
      tate[i] %= mod;
      yoko[j] *= A[i][j];
      yoko[j] %= mod;
    }
  }
  int Q;
  cin>>Q;
  int r, c;
  ll tmp, tmpr, tmpc;
  ll h, two;
  for(int i=0;i<Q;++i) {
    cin>>r>>c;
    r--;
    c--;
    if(A[r][c]==0) {
      if(tatezero[r]+yokozero[c]-1!=zeronum) {
        cout<<0<<endl;
        continue;
      }
    }
    else {
      if(tatezero[r]+yokozero[c]!=zeronum) {
        cout<<0<<endl;
        continue;
      }
    }
    tmp = sumA;
    if(A[r][c]>0) tmp *= A[r][c];
    tmp %= mod;
    h = mod - 2;
    while(h>0) {
      two = 1;
      tmpr = tate[r];
      tmpc = yoko[c];
      while(2*two<h) {
        two *= 2;
        tmpr *= tmpr;
        tmpr %= mod;
        tmpc *= tmpc;
        tmpc %= mod;
      }
      h -= two;
      tmp *= tmpr;
      tmp %= mod;
      tmp *= tmpc;
      tmp %= mod;
    }
    cout<<tmp<<endl;
  }
}

0