結果

問題 No.440 2次元チワワ問題
ユーザー 👑 kmjpkmjp
提出日時 2016-10-29 00:08:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 914 ms / 5,000 ms
コード長 1,838 bytes
コンパイル時間 1,448 ms
コンパイル使用メモリ 163,008 KB
実行使用メモリ 495,140 KB
最終ジャッジ日時 2024-05-03 08:24:39
合計ジャッジ時間 16,886 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 316 ms
494,552 KB
testcase_01 AC 316 ms
494,552 KB
testcase_02 AC 317 ms
494,592 KB
testcase_03 AC 313 ms
494,592 KB
testcase_04 AC 325 ms
494,592 KB
testcase_05 AC 315 ms
494,592 KB
testcase_06 AC 319 ms
494,592 KB
testcase_07 AC 361 ms
494,720 KB
testcase_08 AC 399 ms
494,848 KB
testcase_09 AC 564 ms
494,936 KB
testcase_10 AC 369 ms
494,720 KB
testcase_11 AC 341 ms
494,788 KB
testcase_12 AC 414 ms
494,848 KB
testcase_13 AC 648 ms
494,976 KB
testcase_14 AC 319 ms
494,716 KB
testcase_15 AC 682 ms
494,976 KB
testcase_16 AC 328 ms
494,792 KB
testcase_17 AC 914 ms
495,104 KB
testcase_18 AC 786 ms
495,076 KB
testcase_19 AC 836 ms
495,028 KB
testcase_20 AC 844 ms
495,140 KB
testcase_21 AC 808 ms
495,104 KB
testcase_22 AC 795 ms
495,104 KB
testcase_23 AC 757 ms
495,060 KB
testcase_24 AC 885 ms
495,060 KB
testcase_25 AC 778 ms
495,104 KB
権限があれば一括ダウンロードができます

ソースコード

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 dp[501][501][501];
int U[10101],D[10101],L[10101],R[10101];
ll ret[10101];

int Q;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	FOR(y,H) cin>>S[y];
	
	cin>>Q;
	FOR(i,Q) {
		cin>>U[i]>>L[i]>>D[i]>>R[i];
		U[i]--,D[i]--,L[i]--,R[i]--;
	}
	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;
				dp[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;
				dp[y][z][x]+=ncww;
			}
		}
	}
	FOR(i,Q) {
		for(y=U[i];y<=D[i];y++) ret[i]+=dp[y][L[i]][R[i]];
	}
	ZERO(dp);

	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;
				dp[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;
				dp[x][z][y]+=ncww;
			}
		}
	}
	
	FOR(i,Q) {
		for(x=L[i];x<=R[i];x++) ret[i]+=dp[x][U[i]][D[i]];
		cout<<ret[i]<<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