Submission #170796

#TimeUsernameProblemLanguageResultExecution timeMemory
170796BigChungusStrah (COCI18_strah)C++14
110 / 110
142 ms4344 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> const int N = 2009; struct Nod { int left, right; int g;///greutatea }; int dp[N]; Nod v[N]; int stk[N]; long long ans; string s; void dfs(int nod) { if (nod == 0) return; dfs(v[nod].left); dfs(v[nod].right); int n(v[v[nod].left].g), m(v[v[nod].right].g); v[nod].g = n + m + 1; ans += 1LL * dp[nod] * (dp[nod] + 1) / 2 * (n + 1) * (m + 1) * (1.0 * n / 2 + 1.0 * m / 2 + 1); } int main() { ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> s; s = '$' + s; for (int j = 1; j <= m; ++j) { if (s[j] == '#') dp[j] = 0; else dp[j]++; } memset(v, 0, sizeof v); int top(0); for (int j = 1; j <= m; ++j) {///acum parctic trebuie sa construiesc arborele cartezian while (top && dp[stk[top]] > dp[j]) --top; v[j].left = v[stk[top]].right; v[stk[top]].right = j; stk[++top] = j; } dfs(stk[1]); } cout << ans; return 0; } /* 2 3 .#. ..# */
#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...