Submission #2943455


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

int main(){
    long long i, j, k;
    long long N, M;
    cin >> N >> M;
    vector<string> S(N);
    for(i=0; i<N; i++) cin >> S[i];
    const int MAX = 2000;
    long long left[MAX][MAX];
    long long up[MAX][MAX];
    long long right[MAX][MAX];
    long long down[MAX][MAX];

    long long ans = 0;
    for(i=0; i<N; i++){
        for(j=0; j<M; j++){
            if(S[i][j] == '#'){
                up[i][j] = 0;
                left[i][j] = 0;
                continue;
            }
            if(i==0 || S[i-1][j] == '#'){
                up[i][j] = 0;
            }else{
                up[i][j] = up[i-1][j] + 1;
            }
            if(j==0 || S[i][j-1] == '#'){
                left[i][j] == 0;
            }else{
                left[i][j] = left[i][j-1] + 1;
            }
        }
    }
    for(i=N-1; i>=0; i--){
        for(j=M-1; j>=0; j--){
            if(S[i][j] == '#'){
                down[i][j] = 0;
                right[i][j] = 0;
                continue;
            }
            if(i==N-1 || S[i+1][j] == '#'){
                down[i][j] = 0;
            }else{
                down[i][j] = down[i+1][j] + 1;
            }
            if(j==M-1 || S[i][j+1] == '#'){
                right[i][j] == 0;
            }else{
                right[i][j] = right[i][j+1] + 1;
            }
        }
    }
    for(i=0; i<N; i++){
        for(j=0; j<M; j++){
            ans += (left[i][j] + right[i][j]) * (up[i][j] + down[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task C - 右折
User betrue12
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1625 Byte
Status
Exec Time 248 ms
Memory 129408 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 400 / 400 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 247 ms 129280 KB
02.txt 248 ms 129280 KB
03.txt 248 ms 129280 KB
04.txt 247 ms 129280 KB
05.txt 209 ms 129408 KB
06.txt 210 ms 129408 KB
07.txt 209 ms 129280 KB
08.txt 209 ms 129280 KB
09.txt 195 ms 129280 KB
10.txt 195 ms 129408 KB
11.txt 195 ms 129408 KB
12.txt 195 ms 129280 KB
13.txt 187 ms 129280 KB
14.txt 187 ms 129280 KB
15.txt 195 ms 129408 KB
16.txt 194 ms 129408 KB
17.txt 172 ms 129280 KB
18.txt 172 ms 129280 KB
19.txt 190 ms 129280 KB
20.txt 190 ms 129408 KB
21.txt 208 ms 129408 KB
22.txt 208 ms 129280 KB
23.txt 207 ms 129280 KB
24.txt 208 ms 129280 KB
25.txt 200 ms 129408 KB
26.txt 199 ms 129408 KB
27.txt 199 ms 129280 KB
28.txt 199 ms 129280 KB
29.txt 2 ms 6400 KB
30.txt 2 ms 6400 KB
31.txt 3 ms 8448 KB
32.txt 2 ms 6400 KB
33.txt 2 ms 6400 KB
34.txt 2 ms 6400 KB
35.txt 2 ms 6400 KB
36.txt 2 ms 6400 KB
s1.txt 2 ms 6400 KB
s2.txt 2 ms 6400 KB
s3.txt 2 ms 6400 KB