結果

問題 No.440 2次元チワワ問題
ユーザー 👑 kmjpkmjp
提出日時 2016-10-29 00:02:56
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,736 bytes
コンパイル時間 1,399 ms
コンパイル使用メモリ 161,264 KB
実行使用メモリ 816,512 KB
最終ジャッジ日時 2024-05-03 08:24:03
合計ジャッジ時間 6,757 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 6 ms
8,960 KB
testcase_05 AC 4 ms
6,272 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 116 ms
141,696 KB
testcase_08 AC 171 ms
139,392 KB
testcase_09 AC 542 ms
457,600 KB
testcase_10 AC 135 ms
135,040 KB
testcase_11 AC 49 ms
37,760 KB
testcase_12 AC 219 ms
278,784 KB
testcase_13 MLE -
testcase_14 AC 20 ms
7,424 KB
testcase_15 MLE -
testcase_16 AC 19 ms
5,376 KB
testcase_17 MLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W;
string S[505];
int LR[501][501][501];
int UD[501][501][501];
int Q;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	FOR(y,H) cin>>S[y];
	FOR(y,H) {
		FOR(x,W) {
			int nc=0;
			int ncw=0;
			ll ncww=0;
			for(int z=x;z<W;z++) {
				if(S[y][z]=='c') nc++;
				else ncww+=ncw, ncw+=nc;
				LR[y][x][z]=ncww;
			}
		}
		for(x=W-1;x>=0;x--) {
			int nc=0;
			int ncw=0;
			ll ncww=0;
			for(int z=x;z>=0;z--) {
				if(S[y][z]=='c') nc++;
				else ncww+=ncw, ncw+=nc;
				LR[y][z][x]+=ncww;
			}
		}
	}
	FOR(x,W) {
		FOR(y,H) {
			int nc=0;
			int ncw=0;
			ll ncww=0;
			for(int z=y;z<H;z++) {
				if(S[z][x]=='c') nc++;
				else ncww+=ncw, ncw+=nc;
				UD[x][y][z]=ncww;
			}
		}
		for(y=H-1;y>=0;y--) {
			int nc=0;
			int ncw=0;
			ll ncww=0;
			for(int z=y;z>=0;z--) {
				if(S[z][x]=='c') nc++;
				else ncww+=ncw, ncw+=nc;
				UD[x][z][y]+=ncww;
			}
		}
	}
	
	cin>>Q;
	while(Q--) {
		int L,R,U,D;
		cin>>U>>L>>D>>R;
		ll ret=0;
		U--,D--,L--,R--;
		for(y=U;y<=D;y++) ret+=LR[y][L][R];
		for(x=L;x<=R;x++) ret+=UD[x][U][D];
		cout<<ret<<endl;
	}
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0