結果
問題 |
No.1141 田グリッド
|
ユーザー |
|
提出日時 | 2020-08-01 00:01:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 163 ms / 2,000 ms |
コード長 | 1,163 bytes |
コンパイル時間 | 673 ms |
コンパイル使用メモリ | 75,528 KB |
実行使用メモリ | 16,896 KB |
最終ジャッジ日時 | 2024-07-06 22:25:42 |
合計ジャッジ時間 | 4,906 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
コンパイルメッセージ
main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 6 | main() | ^~~~
ソースコード
#include<iostream> #include<vector> using namespace std; const long mod=1e9+7; int H,W; main() { cin>>H>>W; vector<vector<long> >A(H,vector<long>(W)); for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>A[i][j]; vector<vector<long> >UL(H,vector<long>(W)); vector<vector<long> >UR(H,vector<long>(W)); vector<vector<long> >DL(H,vector<long>(W)); vector<vector<long> >DR(H,vector<long>(W)); for(int i=0;i<H;i++)for(int j=0;j<W;j++) { UL[i][j]=A[i][j]; if(j)UL[i][j]=UL[i][j-1]*A[i][j]%mod; DL[i][j]=UL[i][j]; } for(int i=0;i<H;i++)for(int j=W;j--;) { UR[i][j]=A[i][j]; if(j<W-1)UR[i][j]=UR[i][j+1]*A[i][j]%mod; DR[i][j]=UR[i][j]; } for(int j=0;j<W;j++)for(int i=1;i<H;i++) { UL[i][j]=UL[i][j]*UL[i-1][j]%mod; UR[i][j]=UR[i][j]*UR[i-1][j]%mod; } for(int j=0;j<W;j++)for(int i=H-1;i--;) { DL[i][j]=DL[i][j]*DL[i+1][j]%mod; DR[i][j]=DR[i][j]*DR[i+1][j]%mod; } int Q;cin>>Q; for(;Q--;) { int x,y;cin>>x>>y;x--,y--; long ans=1; if(x-1>=0&&y-1>=0)ans=ans*UL[x-1][y-1]%mod; if(x-1>=0&&y+1<W)ans=ans*UR[x-1][y+1]%mod; if(x+1<H&&y-1>=0)ans=ans*DL[x+1][y-1]%mod; if(x+1<H&&y+1<W)ans=ans*DR[x+1][y+1]%mod; cout<<ans<<endl; } }