結果

問題 No.1141 田グリッド
ユーザー sepa38sepa38
提出日時 2023-03-28 11:18:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,611 bytes
コンパイル時間 4,043 ms
コンパイル使用メモリ 235,528 KB
実行使用メモリ 7,996 KB
最終ジャッジ日時 2023-10-20 06:32:06
合計ジャッジ時間 16,714 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 RE -
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 161 ms
7,688 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 1,130 ms
6,804 KB
testcase_22 AC 1,141 ms
6,804 KB
testcase_23 AC 1,125 ms
6,804 KB
testcase_24 RE -
testcase_25 AC 297 ms
6,540 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 304 ms
6,540 KB
testcase_29 AC 918 ms
6,012 KB
testcase_30 RE -
testcase_31 AC 787 ms
7,332 KB
testcase_32 AC 1,135 ms
6,804 KB
testcase_33 AC 1,117 ms
6,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

long long op(long long a, long long b){
  return a * b % 1000000007;
}

long long e(){
  return 1;
}

int main(){
  long long h, w;
  cin >> h >> w;
  long long a[h][w];
  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      cin >> a[i][j];
    }
  }
  long long mod = 1000000007;
  if (h < w){
    vector<segtree<long long, op, e>> seg;
    for (int i = 0; i < h; i++){
      segtree<long long, op, e> tmp(w);
      for (int j = 0; j < w; j++){
        tmp.set(j, a[i][j]);
      }
      seg.push_back(tmp);
    }
    long long q;
    cin >> q;
    for (int cnt = 0; cnt < q; cnt++){
      long long r, c;
      cin >> r >> c;
      r -= 1;
      c -= 1;
      long long ans = 1;
      for (int i = 0; i < h; i++){
        if (i == r){
          continue;
        }
        ans *= seg[i].prod(0, c) * seg[i].prod(c+1, w) % mod;
        ans %= mod;
      }
      cout << ans << endl;
    }
  } else{
    vector<segtree<long long, op, e>> seg;
    for (int j = 0; j < w; j++){
      segtree<long long, op, e> tmp(h);
      for (int i = 0; i < h; i++){
        tmp.set(i, a[i][j]);
      }
      seg.push_back(tmp);
    }
    long long q;
    cin >> q;
    for (int cnt = 0; cnt < q; cnt++){
      long long r, c;
      cin >> r >> c;
      r -= 1;
      c -= 1;
      long long ans = 1;
      for (int j = 0; j < w; j++){
        if (j == c){
          continue;
        }
        ans *= seg[j].prod(0, r) * seg[j].prod(r+1, w) % mod;
        ans %= mod;
      }
      cout << ans << endl;
    }
  }
}
0