結果
問題 |
No.1141 田グリッド
|
ユーザー |
![]() |
提出日時 | 2021-05-07 19:10:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,846 bytes |
コンパイル時間 | 4,765 ms |
コンパイル使用メモリ | 347,496 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-15 07:21:51 |
合計ジャッジ時間 | 11,816 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 WA * 10 |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <boost/multiprecision/cpp_int.hpp> namespace mp=boost::multiprecision; template<typename type> class field{ int MOD=1000000007; public: function<type(type,type)> add=[this](int a,int b){ long long A=a,B=b; return (A+B)%MOD; }; function<type(type,type)> product=[this](int a,int b){ long long A=a,B=b; return (A*B)%MOD; }; function<bool(type)> in=[this](type a){ int comp; return typeid(comp)==typeid(a) && 0<=a && a<MOD; };//引数が体の要素か否か function<type(type)> add_inverse=[this](int a){ return (-a+MOD)%MOD; }; function<type(type)> product_inverse=[this](int a){ long long temp=a; long long ans=1; int p=MOD-2; while(p>0){ if(p%2){ ans=(ans*temp)%MOD; } temp=(temp*temp)%MOD; p/=2; } int l=ans; return l; }; type one=1,zero=0; field(){ } }; int main(){ int H,W; cin>>H>>W; vector<vector<int>> A(H,vector<int>(W)); for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ cin>>A[i][j]; } } field<int> f; vector<int> R(H),C(W); for(int i=0;i<H;i++){ int temp=1; for(int j=0;j<W;j++){ temp=f.product(temp,A[i][j]); } R[i]=temp; } int ev=1; for(int i=0;i<W;i++){ int temp=1; for(int j=0;j<H;j++){ temp=f.product(temp,A[j][i]); ev=f.product(ev,A[j][i]); } C[i]=temp; } int Q; cin>>Q; for(int i=0;i<Q;i++){ int r,c; cin>>r>>c; cout<<f.product(ev,f.product(A[r-1][c-1],f.product(f.product_inverse(R[r-1]),f.product_inverse(C[c-1]))))<<endl; } }