Submission #848399

# Submission time Handle Problem Language Result Execution time Memory
848399 2023-09-12T12:23:40 Z Charizard2021 Strah (COCI18_strah) C++17
0 / 110
190 ms 4184 KB
#include<bits/stdc++.h>
using namespace std;
long long x(long long k){
    return k * (k + 1)/2;
}
int main(){
    long long n, m;
    cin >> n >> m;
    char grid[n][m];
    for(long long i = 0; i < n; i++){
        for(long long j = 0; j < m; j++){
            cin >> grid[i][j];
        }
    }
    vector<long long> pref(m, 0);
    long long ans = 0;
    for(long long i = 0; i < n; i++){
        for(long long j = 0; j < m; j++){
            if(grid[i][j] == '.'){
                pref[j]++;
            }
            else{
                pref[j] = 0;
            }
        }
        vector<long long> v(m, -1);
        vector<long long> v2(m, m);
        stack<long long> s;
        for(long long j = 0; j < m; j++){
            while(!s.empty() && pref[j] <= pref[s.top()]){
                v[s.top()] = j;
                s.pop();
            }
            s.push(j);
        }
        while(!s.empty()){
            s.pop();
        }
        for(long long j = m - 1; j >= 0; j--){
            while(!s.empty() && pref[j] < pref[s.top()]){
                v2[s.top()] = j;
                s.pop();
            }
            s.push(j);
        }
        for(long long j = 0; j < m; j++){
            long long val = v[j] + 1;
            long long val2 = v2[j] - 1;
            long long length1 = j - val + 1;
            long long length2 = val2 - j + 1;
            ans += (((x(val2 + 1) - x(j)) * length1 - (x(j) - x(val - 1)) * length2) * (x(pref[j])));
        }
    }
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 1456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 138 ms 2816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 80 ms 1880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 190 ms 4184 KB Output isn't correct
2 Halted 0 ms 0 KB -