結果

問題 No.440 2次元チワワ問題
ユーザー Lepton_sLepton_s
提出日時 2016-10-28 23:53:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 606 ms / 5,000 ms
コード長 1,844 bytes
コンパイル時間 2,415 ms
コンパイル使用メモリ 79,816 KB
実行使用メモリ 7,036 KB
最終ジャッジ日時 2023-08-15 21:52:04
合計ジャッジ時間 8,240 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 3 ms
4,384 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 49 ms
4,700 KB
testcase_08 AC 98 ms
5,432 KB
testcase_09 AC 261 ms
6,132 KB
testcase_10 AC 50 ms
5,256 KB
testcase_11 AC 39 ms
4,852 KB
testcase_12 AC 96 ms
5,108 KB
testcase_13 AC 346 ms
5,792 KB
testcase_14 AC 7 ms
4,380 KB
testcase_15 AC 372 ms
6,096 KB
testcase_16 AC 23 ms
4,380 KB
testcase_17 AC 606 ms
6,732 KB
testcase_18 AC 479 ms
6,732 KB
testcase_19 AC 571 ms
6,760 KB
testcase_20 AC 534 ms
7,036 KB
testcase_21 AC 470 ms
6,780 KB
testcase_22 AC 511 ms
6,728 KB
testcase_23 AC 416 ms
6,728 KB
testcase_24 AC 541 ms
6,728 KB
testcase_25 AC 470 ms
6,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<25;
typedef pair<int,int> P;
typedef long long ll;
typedef unsigned long long ull;

#define N 502
#define Q 10000
ll h, w;
vector<string> s(N), s2(N);
ll a[Q], b[Q], c[Q], d[Q];
ll q;
ll res[Q];
ll dp[N][N];

void rot(){
	for(int i = 0; i < q; i++){
		int t;
		t = h-a[i]-1;
		a[i] = b[i];
		b[i] = t;
		t = h-c[i]-1;
		c[i] = d[i];
		d[i] = t;
		swap(b[i], d[i]);
	}
	for(int i = 0; i < N; i++) s2[i] = "";
	for(int i = h-1; i >= 0; i--)
		for(int j = 0; j < w; j++)
			s2[j] += s[i][j];
	swap(s, s2);
	swap(h, w);
}

void solve(){
	//memset(dp, 0, sizeof(dp));
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			dp[j][j] = 0;
			int nc = 0, nw = 0;
			for(int k = j; k < w; k++){
				if(s[i][k]=='c'){
					dp[j][k+1] = dp[j][k];
					nc++;
				} else {
					dp[j][k+1] = dp[j][k]+nw;
					nw += nc;
				}
			}
		}
		for(int l = 0; l < q; l++){
			if(a[l]<=i && i<=c[l]) res[l] += dp[b[l]][d[l]+1];
		}
	}
}

int main(){
	cin>>h>>w;
	for(int i = 0; i < h; i++) cin>>s[i];
	cin>>q;
	for(int i = 0; i < q; i++){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		a[i]--; b[i]--; c[i]--; d[i]--;
	}
	for(int i = 0; i < 4; i++){
		/*cerr<<h<<" "<<w<<endl;
		for(int j = 0; j < h; j++){
			cerr<<s[j]<<endl;
		}
		cerr<<q<<endl;
		for(int j = 0; j < q; j++){
			cerr<<a[j]<<" "<<b[j]<<" "<<c[j]<<" "<<d[j]<<endl;
		}*/
		rot();
		solve();
	}
	for(int i = 0; i < q; i++) cout<<res[i]<<endl;
	return 0;
}
0