結果

問題 No.440 2次元チワワ問題
ユーザー chocoruskchocorusk
提出日時 2020-02-17 09:40:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,214 ms / 5,000 ms
コード長 3,527 bytes
コンパイル時間 1,767 ms
コンパイル使用メモリ 125,192 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 03:45:06
合計ジャッジ時間 16,492 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 4 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 149 ms
5,376 KB
testcase_08 AC 268 ms
5,376 KB
testcase_09 AC 945 ms
5,376 KB
testcase_10 AC 159 ms
5,376 KB
testcase_11 AC 73 ms
5,376 KB
testcase_12 AC 306 ms
5,376 KB
testcase_13 AC 1,228 ms
5,376 KB
testcase_14 AC 9 ms
5,376 KB
testcase_15 AC 1,303 ms
5,376 KB
testcase_16 AC 28 ms
5,376 KB
testcase_17 AC 2,214 ms
5,376 KB
testcase_18 AC 1,273 ms
5,376 KB
testcase_19 AC 1,070 ms
5,376 KB
testcase_20 AC 1,209 ms
5,376 KB
testcase_21 AC 626 ms
5,376 KB
testcase_22 AC 373 ms
5,376 KB
testcase_23 AC 658 ms
5,376 KB
testcase_24 AC 835 ms
5,376 KB
testcase_25 AC 620 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int h, w;
string s[505];
int a[10010], b[10010], c[10010], d[10010];
using Pi=pair<P, int>;
ll ans[10010];
int main()
{
    cin>>h>>w;
    for(int i=0; i<h; i++) cin>>s[i];
    int q; cin>>q;
    vector<Pi> vx(q), vy(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]--;
        vx[i]=Pi(P(a[i], c[i]), i);
        vy[i]=Pi(P(b[i], d[i]), i);
    }
    sort(vx.begin(), vx.end());
    sort(vy.begin(), vy.end());
    for(int i=0; i<h; i++){
        int t=0;
        for(int j=0; j<w; j++){
            ll cntw=0, cnt=0;
            for(int k=j; k<w; k++){
                if(s[i][k]=='c') cnt+=cntw*(cntw-1)/2;
                else cntw++;
                while(t<q && vy[t].first<=P(j, k)){
                    if(vy[t].first==P(j, k) && a[vy[t].second]<=i && i<=c[vy[t].second]){
                        ans[vy[t].second]+=cnt;
                    }
                    t++;
                }
            }
        }
    }
    for(int i=0; i<w; i++){
        int t=0;
        for(int j=0; j<h; j++){
            ll cntw=0, cnt=0;
            for(int k=j; k<h; k++){
                if(s[k][i]=='c') cnt+=cntw*(cntw-1)/2;
                else cntw++;
                while(t<q && vx[t].first<=P(j, k)){
                    if(vx[t].first==P(j, k) && b[vx[t].second]<=i && i<=d[vx[t].second]){
                        ans[vx[t].second]+=cnt;
                    }
                    t++;
                }
            }
        }
    }
    sort(vx.begin(), vx.end(), [](Pi a, Pi b){ return (a.first.second!=b.first.second)?(a.first.second>b.first.second):(a.first.first>b.first.first);});
    sort(vy.begin(), vy.end(), [](Pi a, Pi b){ return (a.first.second!=b.first.second)?(a.first.second>b.first.second):(a.first.first>b.first.first);});
    for(int i=0; i<h; i++){
        int t=0;
        for(int j=w-1; j>=0; j--){
            ll cntw=0, cnt=0;
            for(int k=j; k>=0; k--){
                if(s[i][k]=='c') cnt+=cntw*(cntw-1)/2;
                else cntw++;
                while(t<q && (vy[t].first.second>j || (vy[t].first.second==j && vy[t].first.first>=k))){
                    if(vy[t].first==P(k, j) && a[vy[t].second]<=i && i<=c[vy[t].second]){
                        ans[vy[t].second]+=cnt;
                    }
                    t++;
                }
            }
        }
    }
    for(int i=0; i<w; i++){
        int t=0;
        for(int j=h-1; j>=0; j--){
            ll cntw=0, cnt=0;
            for(int k=j; k>=0; k--){
                if(s[k][i]=='c') cnt+=cntw*(cntw-1)/2;
                else cntw++;
                while(t<q && (vx[t].first.second>j || (vx[t].first.second==j && vx[t].first.first>=k))){
                    if(vx[t].first==P(k, j) && b[vx[t].second]<=i && i<=d[vx[t].second]){
                        ans[vx[t].second]+=cnt;
                    }
                    t++;
                }
            }
        }
    }
    for(int i=0; i<q; i++) cout<<ans[i]<<endl;
	return 0;
}
0