結果
問題 | No.440 2次元チワワ問題 |
ユーザー | 👑 kmjp |
提出日時 | 2016-10-29 00:08:37 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 740 ms / 5,000 ms |
コード長 | 1,838 bytes |
コンパイル時間 | 1,248 ms |
コンパイル使用メモリ | 147,892 KB |
実行使用メモリ | 495,376 KB |
最終ジャッジ日時 | 2023-08-15 21:55:07 |
合計ジャッジ時間 | 12,825 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 173 ms
494,624 KB |
testcase_01 | AC | 172 ms
494,756 KB |
testcase_02 | AC | 172 ms
494,624 KB |
testcase_03 | AC | 172 ms
494,676 KB |
testcase_04 | AC | 182 ms
494,652 KB |
testcase_05 | AC | 172 ms
494,720 KB |
testcase_06 | AC | 175 ms
494,896 KB |
testcase_07 | AC | 221 ms
494,744 KB |
testcase_08 | AC | 267 ms
494,896 KB |
testcase_09 | AC | 425 ms
494,964 KB |
testcase_10 | AC | 252 ms
494,764 KB |
testcase_11 | AC | 195 ms
494,800 KB |
testcase_12 | AC | 277 ms
494,776 KB |
testcase_13 | AC | 485 ms
495,068 KB |
testcase_14 | AC | 175 ms
494,732 KB |
testcase_15 | AC | 521 ms
494,988 KB |
testcase_16 | AC | 186 ms
494,852 KB |
testcase_17 | AC | 740 ms
495,152 KB |
testcase_18 | AC | 638 ms
495,304 KB |
testcase_19 | AC | 649 ms
495,104 KB |
testcase_20 | AC | 654 ms
495,096 KB |
testcase_21 | AC | 654 ms
495,376 KB |
testcase_22 | AC | 647 ms
495,108 KB |
testcase_23 | AC | 633 ms
495,232 KB |
testcase_24 | AC | 737 ms
495,108 KB |
testcase_25 | AC | 617 ms
495,376 KB |
ソースコード
#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; }