Submission #81699

#TimeUsernameProblemLanguageResultExecution timeMemory
81699SaboonStrah (COCI18_strah)C++14
110 / 110
170 ms7992 KiB
#include <iostream> #include <sstream> #include <queue> #include <stack> #include <vector> #include <cstring> #include <cmath> #include <map> #include <unordered_map> #include <set> #include <algorithm> #include <iomanip> #define F first #define S second #define PB push_back #define PF push_front #define MP make_pair using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; const int maxn = 1e5 + 37; int n, m; int a[maxn]; int l[maxn], r[maxn]; ll sum (ll fi, ll se) { return se * (se + 1) / 2 - fi * (fi + 1) / 2; } ll get () { stack <int> s; for (int i = m - 1; i >= 0; i--) { while (!s.empty() and a[s.top()] >= a[i]) s.pop(); if (!s.empty()) r[i] = s.top(); else r[i] = m; s.push (i); } while (!s.empty()) s.pop(); for (int i = 0; i < m; i++) { while (!s.empty() and a[s.top()] > a[i]) s.pop(); if (!s.empty()) l[i] = s.top(); else l[i] = -1; s.push (i); } ll ret = 0; for (int i = 0; i < m; i++) { ll cnt = sum (i - 1, r[i] - 1) * (i - l[i]) + (r[i] - i) * (i - l[i]); cnt -= sum (l[i], i) * (r[i] - i); ret += a[i] * (a[i] + 1) * cnt / 2; } return ret; } string s[maxn]; int main() { ios_base::sync_with_stdio(false); cin >> n >> m; for (int i = 0; i < n; i++) cin >> s[i]; ll ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (s[i][j] == '#') a[j] = 0; else a[j] ++; } ans += get (); } 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...