結果

問題 No.1141 田グリッド
ユーザー motmot
提出日時 2020-08-01 01:50:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,838 bytes
コンパイル時間 1,566 ms
コンパイル使用メモリ 83,748 KB
実行使用メモリ 4,716 KB
最終ジャッジ日時 2023-09-21 06:04:10
合計ジャッジ時間 7,170 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 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,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 192 ms
4,684 KB
testcase_14 AC 191 ms
4,716 KB
testcase_15 AC 189 ms
4,376 KB
testcase_16 AC 186 ms
4,380 KB
testcase_17 AC 187 ms
4,376 KB
testcase_18 AC 126 ms
4,376 KB
testcase_19 AC 126 ms
4,380 KB
testcase_20 AC 129 ms
4,376 KB
testcase_21 AC 189 ms
4,380 KB
testcase_22 AC 188 ms
4,376 KB
testcase_23 AC 189 ms
4,380 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 129 ms
4,380 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 127 ms
4,380 KB
testcase_33 AC 126 ms
4,400 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;
    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