結果

問題 No.1141 田グリッド
ユーザー 夜
提出日時 2021-03-19 20:03:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 1,499 bytes
コンパイル時間 826 ms
コンパイル使用メモリ 96,660 KB
実行使用メモリ 7,500 KB
最終ジャッジ日時 2023-08-11 23:01:27
合計ジャッジ時間 8,407 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,372 KB
testcase_01 AC 3 ms
5,244 KB
testcase_02 AC 2 ms
5,216 KB
testcase_03 AC 3 ms
5,364 KB
testcase_04 AC 3 ms
5,400 KB
testcase_05 AC 3 ms
5,216 KB
testcase_06 AC 3 ms
5,380 KB
testcase_07 AC 3 ms
5,144 KB
testcase_08 AC 5 ms
5,156 KB
testcase_09 AC 5 ms
5,212 KB
testcase_10 AC 5 ms
5,324 KB
testcase_11 AC 7 ms
5,320 KB
testcase_12 AC 5 ms
5,444 KB
testcase_13 AC 191 ms
6,784 KB
testcase_14 AC 195 ms
7,500 KB
testcase_15 AC 188 ms
6,712 KB
testcase_16 AC 180 ms
6,940 KB
testcase_17 AC 180 ms
6,540 KB
testcase_18 AC 126 ms
6,184 KB
testcase_19 AC 123 ms
6,752 KB
testcase_20 AC 124 ms
6,884 KB
testcase_21 AC 190 ms
6,880 KB
testcase_22 AC 185 ms
6,720 KB
testcase_23 AC 186 ms
6,800 KB
testcase_24 AC 128 ms
6,252 KB
testcase_25 AC 129 ms
6,292 KB
testcase_26 AC 128 ms
6,360 KB
testcase_27 AC 130 ms
6,536 KB
testcase_28 AC 130 ms
6,184 KB
testcase_29 AC 129 ms
6,452 KB
testcase_30 AC 129 ms
6,372 KB
testcase_31 AC 125 ms
7,012 KB
testcase_32 AC 130 ms
6,752 KB
testcase_33 AC 127 ms
6,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long mod = 1000000007;
long long m_pow(long long x, long long y) {
	long long ans = 1;
	while (y > 0) {
		if ((y & 1) == 1) {
			ans = ans * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return ans;
}

vector<vector<long long>> a(100010);
long long zx[100010] = {}, zy[100010] = {};
long long mx[100010], my[100010];
int main() {
	int h, w;
	cin >> h >> w;
	long long m = 1, z = 0;
	for (int i = 0; i < h; i++) {
		mx[i] = 1;
	}
	for (int i = 0; i < w; i++) {
		my[i] = 1;
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			long long a1;
			cin >> a1;
			a[i].emplace_back(a1);
			if (a1 != 0) {
				m *= a1, m %= mod;
				mx[i] *= a1, mx[i] %= mod;
				my[j] *= a1, my[j] %= mod;
			}
			else {
				zx[i]++, zy[j]++;
				z++;
			}
		}
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int r, c;
		cin >> r >> c;
		r--, c--;
		int z1 = zx[r] + zy[c];
		if (a[r][c] == 0)z1--;
		if (z - z1 == 0) {
			long long x = m_pow(mx[r], 1000000005);
			long long y = m_pow(my[c], 1000000005);
			long long ans = m;
			ans *= x, ans %= mod;
			ans *= y, ans %= mod;
			if (a[r][c] != 0) {
				ans *= a[r][c], ans %= mod;
			}
			cout << ans << endl;
		}
		else {
			cout << 0 << endl;
		}
	}
}
0