結果
問題 | No.1141 田グリッド |
ユーザー | 👑 AngrySadEight |
提出日時 | 2020-07-31 23:05:34 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,644 bytes |
コンパイル時間 | 1,538 ms |
コンパイル使用メモリ | 175,840 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-06 20:51:30 |
合計ジャッジ時間 | 5,740 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 4 ms
5,376 KB |
testcase_09 | AC | 4 ms
5,376 KB |
testcase_10 | AC | 4 ms
5,376 KB |
testcase_11 | AC | 5 ms
5,376 KB |
testcase_12 | AC | 4 ms
5,376 KB |
testcase_13 | AC | 142 ms
5,376 KB |
testcase_14 | AC | 149 ms
6,912 KB |
testcase_15 | AC | 132 ms
5,376 KB |
testcase_16 | AC | 138 ms
5,376 KB |
testcase_17 | AC | 131 ms
5,376 KB |
testcase_18 | AC | 119 ms
5,376 KB |
testcase_19 | AC | 121 ms
5,376 KB |
testcase_20 | AC | 121 ms
5,376 KB |
testcase_21 | AC | 141 ms
5,376 KB |
testcase_22 | AC | 133 ms
5,376 KB |
testcase_23 | AC | 135 ms
5,376 KB |
testcase_24 | AC | 123 ms
5,376 KB |
testcase_25 | AC | 121 ms
5,376 KB |
testcase_26 | AC | 123 ms
5,376 KB |
testcase_27 | AC | 128 ms
5,376 KB |
testcase_28 | AC | 126 ms
5,376 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 121 ms
5,376 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define repr(i,n) for(int i = (int)(n); i >= 0; i--) #define all(v) v.begin(),v.end() typedef long long ll; ll moddividing(ll x,ll y){ vector<ll> vec(30); rep(i,30){ vec[i] = y; y = y * y % 1000000007; } ll c = x; c = c * vec[0] % 1000000007; c = c * vec[2] % 1000000007; c = c * vec[9] % 1000000007; c = c * vec[11] % 1000000007; c = c * vec[14] % 1000000007; c = c * vec[15] % 1000000007; c = c * vec[17] % 1000000007; c = c * vec[19] % 1000000007; c = c * vec[20] % 1000000007; c = c * vec[23] % 1000000007; c = c * vec[24] % 1000000007; c = c * vec[25] % 1000000007; c = c * vec[27] % 1000000007; c = c * vec[28] % 1000000007; c = c * vec[29] % 1000000007; return c; } int main(){ ll H,W; cin >> H >> W; vector<vector<ll> > A(H, vector<ll> (W)); rep(i,H){ rep(j,W){ cin >> A[i][j]; } } ll line_zero_count = 0; ll row_zero_count = 0; vector<ll> line_has_zero(H, 0); vector<ll> row_has_zero(W, 0); ll more_than_two_line_zero_count = 0; ll more_than_two_row_zero_count = 0; vector<ll> line(H); vector<ll> row(W); rep(i,H){ line[i] = 1; rep(j,W){ if (A[i][j] != 0) line[i] = (line[i] * A[i][j]) % 1000000007; } } rep(j,W){ row[j] = 1; rep(i,H){ if (A[i][j] != 0) row[j] = (row[j] * A[i][j]) % 1000000007; } } ll all = 1; rep(i,H){ rep(j,W){ if (A[i][j] != 0) all = (all * A[i][j]) % 1000000007; else{ if (!line_has_zero[i]){ line_zero_count++; } line_has_zero[i]++; if (!row_has_zero[j]){ row_zero_count++; } row_has_zero[j]++; } } } ll Q; cin >> Q; rep(i,Q){ ll r,c; cin >> r >> c; r--; c--; if (line_zero_count == 0 && row_zero_count == 0){ ll x = (all * A[r][c]) % 1000000007; ll y = (line[r] * row[c]) % 1000000007; cout << moddividing(x, y) << endl; } else if (line_zero_count == 1 && row_zero_count == 1){ if (line_has_zero[r] >= 1 || row_has_zero[c] >= 1){ if (A[r][c] == 0){ ll x = all % 1000000007; ll y = (line[r] * row[c]) % 1000000007; cout << moddividing(x, y) << endl; } else{ ll x = (all * A[r][c]) % 1000000007; ll y = (line[r] * row[c]) % 1000000007; cout << moddividing(x, y) << endl; } } else{ cout << 0 << endl; } } else if (line_zero_count >= 2 && row_zero_count >= 2){ if (line_has_zero[r] >= row_zero_count - 1 && row_has_zero[c] >= line_zero_count - 1){ if (A[r][c] == 0){ ll x = all % 1000000007; ll y = (line[r] * row[c]) % 1000000007; cout << moddividing(x, y) << endl; } else{ ll x = (all * A[r][c]) % 1000000007; ll y = (line[r] * row[c]) % 1000000007; cout << moddividing(x, y) << endl; } } else{ cout << 0 << endl; } } } }