結果

問題 No.440 2次元チワワ問題
ユーザー 👑 kmjpkmjp
提出日時 2016-10-29 00:13:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 470 ms / 5,000 ms
コード長 1,631 bytes
コンパイル時間 1,171 ms
コンパイル使用メモリ 146,904 KB
実行使用メモリ 494,284 KB
最終ジャッジ日時 2023-08-15 21:55:50
合計ジャッジ時間 7,260 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,624 KB
testcase_01 AC 3 ms
9,568 KB
testcase_02 AC 3 ms
9,692 KB
testcase_03 AC 3 ms
7,532 KB
testcase_04 AC 18 ms
83,672 KB
testcase_05 AC 13 ms
56,908 KB
testcase_06 AC 9 ms
36,204 KB
testcase_07 AC 80 ms
201,444 KB
testcase_08 AC 121 ms
216,596 KB
testcase_09 AC 244 ms
366,064 KB
testcase_10 AC 98 ms
285,160 KB
testcase_11 AC 62 ms
219,588 KB
testcase_12 AC 106 ms
268,772 KB
testcase_13 AC 265 ms
396,104 KB
testcase_14 AC 16 ms
63,096 KB
testcase_15 AC 287 ms
415,296 KB
testcase_16 AC 19 ms
20,164 KB
testcase_17 AC 470 ms
494,068 KB
testcase_18 AC 348 ms
494,284 KB
testcase_19 AC 371 ms
494,144 KB
testcase_20 AC 452 ms
494,148 KB
testcase_21 AC 382 ms
494,052 KB
testcase_22 AC 341 ms
494,140 KB
testcase_23 AC 320 ms
494,168 KB
testcase_24 AC 408 ms
494,208 KB
testcase_25 AC 337 ms
494,152 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, ncw=0, ncww=0;
			int nw=0, nww=0, nwwc=0;
			for(int z=x;z<W;z++) {
				if(S[y][z]=='c') {
					nc++;
					nwwc+=nww;
				}
				else {
					ncww+=ncw, ncw+=nc;
					nww+=nw, nw++;
				}
				dp[y][x][z]=ncww+nwwc;
			}
		}
	}
	FOR(i,Q) {
		for(y=U[i];y<=D[i];y++) ret[i]+=dp[y][L[i]][R[i]];
	}

	FOR(x,W) {
		FOR(y,H) {
			int nc=0, ncw=0, ncww=0;
			int nw=0, nww=0, nwwc=0;
			for(int z=y;z<H;z++) {
				if(S[z][x]=='c') {
					nc++;
					nwwc+=nww;
				}
				else {
					ncww+=ncw, ncw+=nc;
					nww+=nw, nw++;
				}
				dp[x][y][z]=ncww+nwwc;
			}
		}
	}
	
	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