Submission #460803

#TimeUsernameProblemLanguageResultExecution timeMemory
460803grtStrah (COCI18_strah)C++17
110 / 110
158 ms19972 KiB
#include <bits/stdc++.h> #define PB push_back #define ST first #define ND second #define _ ios_base::sync_with_stdio(0); cin.tie(0); //mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); using namespace std; using ll = long long; using pi = pair<int,int>; using vi = vector<int>; const int nax = 2010; int n, m; char t[nax][nax]; int up[nax][nax]; int main() {_ cin >> n >> m; for(int i = 1; i <= n; ++i) { for(int j = 1; j <= m; ++j) { cin >> t[i][j]; if(t[i][j] == '.') up[i][j] = up[i - 1][j] + 1; else up[i][j] = 0; } } ll ans = 0; for(int i = 1; i <= n; ++i) { vector<pi> S = {{-1, 0}}; ll cur = 0; ll sum = 0; for(int j = 1; j <= m; ++j) { while((int)S.size() > 0 && S.back().ST >= up[i][j]) { int p1 = S.back().ND; int p2 = S[(int)S.size() - 2].ND; cur -= 1LL * (S.back().ST * (S.back().ST + 1) / 2) * (p1 - p2) * (2*(j-1) - p1 - p2 + 1) / 2; sum -= 1LL * (p1 - p2) * S.back().ST * (S.back().ST + 1) / 2; S.pop_back(); } int p1 = j; int p2 = S.back().ND; S.emplace_back(up[i][j], j); cur += 1LL * (up[i][j] * (up[i][j] + 1) / 2) * ((p1 - p2) * (2*j-p1-p2 + 1)) / 2; cur += sum; sum += 1LL * (p1 - p2) * up[i][j] * (up[i][j] + 1) / 2; ans += cur; } } cout << ans; }
#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...