結果

問題 No.1141 田グリッド
ユーザー umezoumezo
提出日時 2020-07-31 22:18:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,047 bytes
コンパイル時間 2,116 ms
コンパイル使用メモリ 201,856 KB
実行使用メモリ 4,560 KB
最終ジャッジ日時 2023-09-20 23:51:49
合計ジャッジ時間 6,689 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 3 ms
4,384 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 145 ms
4,380 KB
testcase_14 AC 149 ms
4,560 KB
testcase_15 AC 128 ms
4,380 KB
testcase_16 AC 129 ms
4,412 KB
testcase_17 AC 127 ms
4,376 KB
testcase_18 AC 129 ms
4,376 KB
testcase_19 AC 126 ms
4,376 KB
testcase_20 AC 126 ms
4,376 KB
testcase_21 AC 128 ms
4,380 KB
testcase_22 AC 128 ms
4,380 KB
testcase_23 AC 128 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 -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:37:6: 警告: ‘tmp’ may be used uninitialized [-Wmaybe-uninitialized]
   37 |   ll tmp;
      |      ^~~

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const int MOD=1e9+7;

ll modinv(ll a,ll m){
  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(){
  ll h,w;
  cin>>h>>w;
  
  ll A[h+1][w+1];
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++) cin>>A[i][j];
  }
  
  ll all=1;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++) all=(all*A[i][j])%MOD;
  }
  
  vector<ll> B(h+1),C(w+1);
  ll tmp;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(j==1) tmp=A[i][1];
      else tmp=(tmp*A[i][j])%MOD;
    }
    B[i]=modinv(tmp,MOD);
  }
  for(int j=1;j<=w;j++){
    for(int i=1;i<=h;i++){
      if(i==1) tmp=A[1][j];
      else tmp=(tmp*A[i][j])%MOD;
    }
    C[j]=modinv(tmp,MOD);
  }
  
  ll q;
  cin>>q;
  
  ll r,c;
  rep(i,q){
    cin>>r>>c; 
    ll ans=(((all*B[r]%MOD)*C[c]%MOD)*A[r][c])%MOD;
    cout<<ans<<endl;
  }

  return 0;
}
0