Submission #848401

#TimeUsernameProblemLanguageResultExecution timeMemory
848401Charizard2021Strah (COCI18_strah)C++17
110 / 110
232 ms8404 KiB
#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()]){ v2[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()]){ v[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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...