結果
問題 | No.1141 田グリッド |
ユーザー |
![]() |
提出日時 | 2020-07-31 22:14:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 178 ms / 2,000 ms |
コード長 | 4,072 bytes |
コンパイル時間 | 3,314 ms |
コンパイル使用メモリ | 202,208 KB |
最終ジャッジ日時 | 2025-01-12 10:28:22 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
#include <bits/stdc++.h>using namespace std;inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}typedef long long ll;typedef vector<int> VI;typedef vector<VI> VVI;typedef vector<long long> VL;typedef vector<vector<long long>> VVL;typedef vector<string> VS;typedef pair<int, int> P;typedef tuple<int,int,int> tpl;#define ALL(a) (a).begin(),(a).end()#define SORT(c) sort((c).begin(),(c).end())#define REVERSE(c) reverse((c).begin(),(c).end())#define EXIST(m,v) (m).find((v)) != (m).end()#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()#define FOR(i,a,b) for(int i=(a);i<(b);++i)#define REP(i,n) FOR(i,0,n)#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)#define RREP(i,n) RFOR(i,n,0)#define en "\n"constexpr double EPS = 1e-9;constexpr double PI = 3.1415926535897932;constexpr int INF = 2147483647;constexpr long long LINF = 1LL<<60;constexpr long long MOD = 1000000007; // 998244353;#define dump(x) cerr << #x << " = " << (x) << endl;#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }struct mint {long long x;mint(long long x=0):x((x%MOD+MOD)%MOD){}mint operator-() const { return mint(-x);}mint& operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;}mint& operator-=(const mint a) {if ((x += MOD-a.x) >= MOD) x -= MOD;return *this;}mint& operator*=(const mint a) {(x *= a.x) %= MOD;if(x < 0) x += MOD;return *this;}mint operator+(const mint a) const {mint res(*this);return res+=a;}mint operator-(const mint a) const {mint res(*this);return res-=a;}mint operator*(const mint a) const {mint res(*this);return res*=a;}mint pow(long long t) const {if (!t) return 1;mint a = pow(t>>1);a *= a;if (t&1) a *= *this;return a;}// for prime MODmint inv() const {return pow(MOD-2);}mint& operator/=(const mint a) {return (*this) *= a.inv();}mint operator/(const mint a) const {mint res(*this);return res/=a;}};void Main(){int H,W; cin >> H >> W;vector<int> hz(H,0), wz(W,0);int nz = 0;ll A[H][W];REP(i,H)REP(j,W){cin >> A[i][j];if(A[i][j] == 0){hz[i]++; wz[j]++;nz++;}}mint s[4][H+1][W+1];REP(j,4)REP(i,H+1) s[j][i][0] = 1;REP(j,4)REP(i,W+1) s[j][0][i] = 1;REP(i,H)REP(j,W){if(s[0][i+1][j].x==0 || s[0][i][j+1].x==0) s[0][i+1][j+1] = 0;else s[0][i+1][j+1] = s[0][i+1][j]*s[0][i][j+1]/s[0][i][j]*A[i][j];}REP(i,H)REP(j,W){if(s[1][i+1][j].x==0 || s[1][i][j+1].x==0) s[1][i+1][j+1] = 0;else s[1][i+1][j+1] = s[1][i+1][j]*s[1][i][j+1]/s[1][i][j]*A[H-1-i][j];}REP(i,H)REP(j,W){if(s[2][i+1][j].x==0 || s[2][i][j+1].x==0) s[2][i+1][j+1] = 0;else s[2][i+1][j+1] = s[2][i+1][j]*s[2][i][j+1]/s[2][i][j]*A[H-1-i][W-1-j];}REP(i,H)REP(j,W){if(s[3][i+1][j].x==0 || s[3][i][j+1].x==0) s[3][i+1][j+1] = 0;else s[3][i+1][j+1] = s[3][i+1][j]*s[3][i][j+1]/s[3][i][j]*A[i][W-1-j];}int Q; cin >> Q;REP(_,Q){int r,c; cin >> r >> c;VI h{r-1,H-r,H-r,r-1}, w{c-1,c-1,W-c,W-c};mint ans(1); REP(i,4) ans *= s[i][h[i]][w[i]];cout << ans.x << en;}return;}int main(void){cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);int t=1; //cin>>t;REP(_,t) Main();return 0;}