結果

問題 No.1141 田グリッド
ユーザー zelnyokzelnyok
提出日時 2020-07-31 22:04:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 3,234 bytes
コンパイル時間 1,404 ms
コンパイル使用メモリ 137,348 KB
実行使用メモリ 19,476 KB
最終ジャッジ日時 2023-09-20 23:27:24
合計ジャッジ時間 5,562 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 9 ms
4,376 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 68 ms
8,128 KB
testcase_14 AC 98 ms
19,476 KB
testcase_15 AC 103 ms
7,856 KB
testcase_16 AC 103 ms
7,808 KB
testcase_17 AC 102 ms
7,780 KB
testcase_18 AC 102 ms
7,860 KB
testcase_19 AC 101 ms
7,792 KB
testcase_20 AC 102 ms
7,912 KB
testcase_21 AC 103 ms
7,860 KB
testcase_22 AC 103 ms
7,856 KB
testcase_23 AC 104 ms
7,864 KB
testcase_24 AC 102 ms
7,864 KB
testcase_25 AC 101 ms
7,952 KB
testcase_26 AC 102 ms
7,912 KB
testcase_27 AC 101 ms
8,212 KB
testcase_28 AC 100 ms
7,784 KB
testcase_29 AC 102 ms
7,860 KB
testcase_30 AC 103 ms
7,868 KB
testcase_31 AC 102 ms
7,728 KB
testcase_32 AC 102 ms
7,992 KB
testcase_33 AC 102 ms
7,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

constexpr lnt MOD = 1e9+7;
struct mint
{
	lnt v;
	mint():v(0){}
	mint(lnt v):v((v+MOD)%MOD){}
	mint operator-()const{ return mint(0) - *this; }
	mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this; }
	mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this; }
	mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this; }
	mint& operator/=(const mint& a){ (*this) *= a.inv(); return *this; }
	mint operator+(const mint& a)const{ return mint(*this) += a; }
	mint operator-(const mint& a)const{ return mint(*this) -= a; }
	mint operator*(const mint& a)const{ return mint(*this) *= a; }
	mint operator/(const mint& a)const{ return mint(*this) /= a; }
	bool operator<(const mint& a)const{ return v < a.v; }
	bool operator==(const mint& a)const{ return v == a.v; }
	mint pow(lnt k)const{ mint r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }
	mint inv()const{ return pow(MOD-2); }
	static mint comb(lnt n, lnt k) { if(n-k<k) k=n-k; mint num(1), dom(1); for(int i=0;i<k;i++) { num*=n-i; dom*=i+1; } return num/dom; }
	static std::vector<mint> construct_comb(int n) {
		std::vector<mint> c(n+1); mint a = 1; c[0] = a; for(int i=1;i<=n;i++) { a = a*mint(n+1-i)/i; c[i] = a; } return c;
	}
	static std::vector<mint> construct_fact(int n) { std::vector<mint> f(n+1,1); for(int i=2;i<=n;i++) f[i]=f[i-1]*i; return f; }
};
std::istream& operator>>(std::istream&i,mint&a){ lnt t; i>>t; a=mint(t); return i; }
std::ostream& operator<<(std::ostream&o,const mint&a){ o<<a.v; return o; }


int main() {
	int h,w;
	std::cin >> h >> w;
	std::vector<std::vector<lnt> > g(h,std::vector<lnt>(w));
	rep(i,h) rep(j,w) std::cin >> g[i][j];
	std::vector<std::vector<std::vector<mint> > > A(4,std::vector<std::vector<mint> >(h,std::vector<mint>(w)));
	rep(k,4) rep(i,h) rep(j,w) A[k][i][j]=mint(g[i][j]);
	rep(k,4) {
		rep(x,h) rep(y,w) {
			int i=(k&1)?x:h-x-1;
			int j=(k>=2)?y:w-y-1;
			if(x==0&&y==0) A[k][i][j]=mint(g[i][j]);
			else if(x==0) A[k][i][j]=mint(g[i][j])*A[k][i][(k>1)?j-1:j+1];
			else if(y==0) A[k][i][j]=mint(g[i][j])*A[k][(k&1)?i-1:i+1][j];
			else {
				A[k][i][j]=A[k][(k&1)?i-1:i+1][j]*mint(g[i][j])*A[k][i][(k>=2)?j-1:j+1]/A[k][(k&1)?i-1:i+1][(k>=2)?j-1:j+1];
			}
		}
	}
	debug(A[0]);
	int q;
	std::cin >> q;
	rep(qq,q) {
		int r,c;
		std::cin >> r >> c;
		r--;c--;
		mint ans=1;
		debug(r,c);
		if(r>0&&c>0) ans*=A[3][r-1][c-1];
		if(r>0&&c<w-1) ans*=A[1][r-1][c+1];
		if(r<h-1&&c>0) ans*=A[2][r+1][c-1];
		if(r<h-1&&c<w-1) ans*=A[0][r+1][c+1];
		print(ans);
	}
}
0