Submission #366271

#TimeUsernameProblemLanguageResultExecution timeMemory
366271wiwihoStrah (COCI18_strah)C++14
110 / 110
130 ms20076 KiB
#include <bits/stdc++.h> #define eb emplace_back #define printv(a, b) {\ bool ps = false;\ for(auto pv : a){\ if(ps) b << ' '; ps = true;\ b << pv;\ }\ b << "\n";\ } #define iter(a) a.begin(), a.end() #define lsort(a) sort(iter(a)) #define mp make_pair #define F first #define S second using namespace std; typedef long long ll; using pii = pair<int, int>; struct qq{ int l, lh, h; qq(int l = 0, int lh = 0, int h = 0): l(l), lh(lh), h(h) {} }; ostream& operator<<(ostream& o, qq now){ return o << '(' << now.l << ',' << now.lh << ',' << now.h << ')'; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<vector<int>> a(n, vector<int>(m + 1)); for(int i = 0; i < n; i++){ string s; cin >> s; for(int j = 0; j < m; j++){ if(s[j] == '#') continue; a[i][j] = 1; if(i && a[i - 1][j]) a[i][j] += a[i - 1][j]; } } //for(int i = 0; i < n; i++) printv(a[i], cerr); vector<ll> f(m + 1); for(ll i = 1; i <= m; i++){ f[i] = f[i - 1] + i * (i + 1) / 2; } ll ans = 0; for(int i = 0; i < n; i++){ stack<qq> st; for(int j = 0; j <= m; j++){ int l = j; while(!st.empty() && st.top().h >= a[i][j]){ qq now = st.top(); st.pop(); l = now.l; ll len = j - now.l; ll th = max(now.lh, a[i][j]); ll h = now.h; ll tans = f[len] * (th + 1 + h) * (h - th) / 2; //cerr << i << " " << j << " " << len << " " // << h << " " << now << " " << tans << "\n"; ans += tans; } int lh = st.empty() ? 0 : st.top().h; st.push(qq(l, lh, a[i][j])); } } cout << ans << "\n"; return 0; }
#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...