結果

問題 No.1141 田グリッド
ユーザー ytftytft
提出日時 2021-05-07 19:10:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,846 bytes
コンパイル時間 3,979 ms
コンパイル使用メモリ 376,696 KB
実行使用メモリ 5,896 KB
最終ジャッジ日時 2023-10-13 10:16:42
合計ジャッジ時間 12,036 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 2 ms
4,368 KB
testcase_07 AC 1 ms
4,372 KB
testcase_08 AC 4 ms
4,368 KB
testcase_09 AC 3 ms
4,368 KB
testcase_10 AC 4 ms
4,368 KB
testcase_11 AC 5 ms
4,368 KB
testcase_12 AC 4 ms
4,368 KB
testcase_13 AC 191 ms
4,372 KB
testcase_14 AC 202 ms
5,896 KB
testcase_15 AC 188 ms
4,368 KB
testcase_16 AC 187 ms
4,372 KB
testcase_17 AC 183 ms
4,368 KB
testcase_18 AC 182 ms
4,368 KB
testcase_19 AC 186 ms
4,368 KB
testcase_20 AC 186 ms
4,372 KB
testcase_21 AC 189 ms
4,368 KB
testcase_22 AC 188 ms
4,372 KB
testcase_23 AC 188 ms
4,372 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
namespace mp=boost::multiprecision;

template<typename type>
class field{
    int MOD=1000000007;
public:
    function<type(type,type)> add=[this](int a,int b){
        long long A=a,B=b;
        return (A+B)%MOD;
    };
    function<type(type,type)> product=[this](int a,int b){
        long long A=a,B=b;
        return (A*B)%MOD;
    };
    function<bool(type)> in=[this](type a){
        int comp;
        return typeid(comp)==typeid(a) && 0<=a && a<MOD;
    };//引数が体の要素か否か
    function<type(type)> add_inverse=[this](int a){
        return (-a+MOD)%MOD;
    };
    function<type(type)> product_inverse=[this](int a){
        long long temp=a;
        long long ans=1;
        int p=MOD-2;
        while(p>0){
            if(p%2){
                ans=(ans*temp)%MOD;
            }
            temp=(temp*temp)%MOD;
            p/=2;
        }
        int l=ans;
        return l;
    };
    type one=1,zero=0;
    field(){
    }
};

int main(){
    int H,W;
    cin>>H>>W;
    vector<vector<int>> A(H,vector<int>(W));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>A[i][j];
        }
    }
    field<int> f;
    vector<int> R(H),C(W);
    for(int i=0;i<H;i++){
        int temp=1;
        for(int j=0;j<W;j++){
            temp=f.product(temp,A[i][j]);
        }
        R[i]=temp;
    }
    int ev=1;
    for(int i=0;i<W;i++){
        int temp=1;
        for(int j=0;j<H;j++){
            temp=f.product(temp,A[j][i]);
            ev=f.product(ev,A[j][i]);
        }
        C[i]=temp;
    }
    int Q;
    cin>>Q;
    for(int i=0;i<Q;i++){
        int r,c;
        cin>>r>>c;
        cout<<f.product(ev,f.product(A[r-1][c-1],f.product(f.product_inverse(R[r-1]),f.product_inverse(C[c-1]))))<<endl;
    }
}
0