結果

問題 No.1141 田グリッド
ユーザー 沙耶花沙耶花
提出日時 2020-07-31 21:38:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 223 ms / 2,000 ms
コード長 1,019 bytes
コンパイル時間 2,303 ms
コンパイル使用メモリ 206,620 KB
実行使用メモリ 6,872 KB
最終ジャッジ日時 2023-09-20 22:13:08
合計ジャッジ時間 6,718 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 31 ms
4,408 KB
testcase_14 AC 36 ms
6,872 KB
testcase_15 AC 129 ms
4,812 KB
testcase_16 AC 120 ms
4,768 KB
testcase_17 AC 92 ms
4,856 KB
testcase_18 AC 99 ms
4,792 KB
testcase_19 AC 118 ms
4,804 KB
testcase_20 AC 118 ms
4,748 KB
testcase_21 AC 221 ms
4,740 KB
testcase_22 AC 221 ms
4,792 KB
testcase_23 AC 221 ms
4,740 KB
testcase_24 AC 181 ms
4,788 KB
testcase_25 AC 49 ms
4,376 KB
testcase_26 AC 99 ms
4,756 KB
testcase_27 AC 91 ms
4,732 KB
testcase_28 AC 49 ms
4,376 KB
testcase_29 AC 178 ms
4,776 KB
testcase_30 AC 97 ms
4,712 KB
testcase_31 AC 146 ms
4,796 KB
testcase_32 AC 223 ms
4,732 KB
testcase_33 AC 220 ms
4,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000002

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++){
			scanf("%d",&A[i][j]);
		}
	}
	if(H>W){
		vector<vector<int>> B(W,vector<int>(H));
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				B[j][i] = A[i][j];
			}
		}
		A = B;
	}
	
	vector<vector<int>> Sl = A,Sr = A;
	
	for(int i=0;i<Sl.size();i++){
		for(int j=1;j<Sl[i].size();j++){
			Sl[i][j] = mod(Sl[i][j] * Sl[i][j-1]);
		}
		for(int j=Sr[i].size()-2;j>=0;j--){
			Sr[i][j] = mod(Sr[i][j] * Sr[i][j+1]);
		}
	}
	
	int Q;
	cin>>Q;
	
	for(int i=0;i<Q;i++){
		int r,c;
		scanf("%d %d",&r,&c);
		r--;c--;
		if(H>W)swap(r,c);
		int ans = 1;
		for(int j=0;j<A.size();j++){
			if(j==r)continue;
			if(c!=0)ans = mod(ans * Sl[j][c-1]);
			if(c+1!=A[j].size())ans = mod(ans * Sr[j][c+1]);
		}
		printf("%d\n",ans);
	}
	
	

	return 0;
}
0