結果

問題 No.1141 田グリッド
ユーザー leaf_1415leaf_1415
提出日時 2020-07-31 21:51:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 2,159 bytes
コンパイル時間 676 ms
コンパイル使用メモリ 76,596 KB
実行使用メモリ 13,836 KB
最終ジャッジ日時 2023-09-20 22:56:21
合計ジャッジ時間 4,714 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
11,476 KB
testcase_01 AC 3 ms
11,460 KB
testcase_02 AC 3 ms
11,552 KB
testcase_03 AC 3 ms
11,768 KB
testcase_04 AC 3 ms
11,568 KB
testcase_05 AC 3 ms
11,552 KB
testcase_06 AC 3 ms
11,668 KB
testcase_07 AC 3 ms
11,484 KB
testcase_08 AC 4 ms
11,532 KB
testcase_09 AC 3 ms
11,656 KB
testcase_10 AC 4 ms
11,768 KB
testcase_11 AC 4 ms
11,628 KB
testcase_12 AC 4 ms
11,524 KB
testcase_13 AC 95 ms
13,352 KB
testcase_14 AC 96 ms
13,836 KB
testcase_15 AC 93 ms
12,256 KB
testcase_16 AC 92 ms
12,640 KB
testcase_17 AC 92 ms
12,564 KB
testcase_18 AC 92 ms
12,436 KB
testcase_19 AC 92 ms
12,260 KB
testcase_20 AC 91 ms
12,272 KB
testcase_21 AC 94 ms
12,560 KB
testcase_22 AC 94 ms
12,356 KB
testcase_23 AC 97 ms
12,360 KB
testcase_24 AC 94 ms
12,432 KB
testcase_25 AC 93 ms
12,308 KB
testcase_26 AC 92 ms
12,268 KB
testcase_27 AC 91 ms
12,256 KB
testcase_28 AC 95 ms
12,480 KB
testcase_29 AC 93 ms
12,436 KB
testcase_30 AC 91 ms
12,276 KB
testcase_31 AC 93 ms
12,436 KB
testcase_32 AC 97 ms
12,356 KB
testcase_33 AC 94 ms
12,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint Q;
llint h, w;
llint a[300005], lu[300005], ru[300005], ld[300005], rd[300005];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

llint get(llint x, llint y)
{
	return y*(w+2)+x;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> h >> w;
	llint mul = 1;
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			cin >> a[get(x, y)];
		}
	}
	for(int y = 0; y <= h+1; y++){
		for(int x = 0; x <= w+1; x++){
			lu[get(x, y)] = ru[get(x, y)] = ld[get(x, y)] = rd[get(x, y)] = 1;
		}
	}
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			lu[get(x, y)] = lu[get(x-1, y)] * a[get(x, y)] % mod;
			ld[get(x, y)] = ld[get(x-1, y)] * a[get(x, y)] % mod;
		}
		for(int x = w; x >= 1; x--){
			ru[get(x, y)] = ru[get(x+1, y)] * a[get(x, y)] % mod;
			rd[get(x, y)] = rd[get(x+1, y)] * a[get(x, y)] % mod;
		}
	}
	for(int x = 1; x <= w; x++){
		for(int y = 1; y <= h; y++){
			lu[get(x, y)] *= lu[get(x, y-1)], lu[get(x, y)] %= mod;
			ru[get(x, y)] *= ru[get(x, y-1)], ru[get(x, y)] %= mod;
		}
		for(int y = h; y >= 1; y--){
			ld[get(x, y)] *= ld[get(x, y+1)], ld[get(x, y)] %= mod;
			rd[get(x, y)] *= rd[get(x, y+1)], rd[get(x, y)] %= mod;
		}
	}
	
	cin >> Q;
	llint x, y;
	for(int i = 0; i < Q; i++){
		cin >> y >> x;
		llint ans = lu[get(x-1, y-1)] * ru[get(x+1, y-1)] % mod;
		ans *= ld[get(x-1, y+1)] * rd[get(x+1, y+1)] % mod, ans %= mod;
		cout << ans << endl;
	}

	return 0;
}
0