結果
問題 | No.1141 田グリッド |
ユーザー | 👑 AngrySadEight |
提出日時 | 2020-07-31 22:37:39 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,457 bytes |
コンパイル時間 | 1,436 ms |
コンパイル使用メモリ | 176,396 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-06 19:52:19 |
合計ジャッジ時間 | 5,311 ms |
ジャッジサーバーID (参考情報) |
judge3 / 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 | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 4 ms
5,376 KB |
testcase_09 | AC | 3 ms
5,376 KB |
testcase_10 | AC | 4 ms
5,376 KB |
testcase_11 | AC | 5 ms
5,376 KB |
testcase_12 | AC | 3 ms
5,376 KB |
testcase_13 | AC | 131 ms
5,376 KB |
testcase_14 | AC | 131 ms
6,784 KB |
testcase_15 | AC | 127 ms
5,376 KB |
testcase_16 | AC | 130 ms
5,376 KB |
testcase_17 | AC | 131 ms
5,376 KB |
testcase_18 | AC | 118 ms
5,376 KB |
testcase_19 | AC | 119 ms
5,376 KB |
testcase_20 | AC | 111 ms
5,376 KB |
testcase_21 | AC | 123 ms
5,376 KB |
testcase_22 | AC | 124 ms
5,376 KB |
testcase_23 | AC | 123 ms
5,376 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 115 ms
5,376 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
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, false); vector<ll> row_has_zero(W, false); 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_has_zero[i] = true; line_zero_count++; } if (!row_has_zero[j]){ row_has_zero[j] = true; row_zero_count++; } } } } 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 >= 2 && row_zero_count >= 2){ cout << 0 << endl; } else{ if (line_zero_count == 1 && row_zero_count == 1){ if (line_has_zero[r] || row_has_zero[c]){ 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 == 1 && row_zero_count >= 2){ if (line_has_zero[r]){ 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 == 1){ if (row_has_zero[c]){ ll x = (all * A[r][c]) % 1000000007; ll y = (line[r] * row[c]) % 1000000007; cout << moddividing(x, y) << endl; } else cout << 0 << endl; } } } }