Submission #92698

#TimeUsernameProblemLanguageResultExecution timeMemory
92698KastandaStrah (COCI18_strah)C++11
110 / 110
113 ms24156 KiB
#include<bits/stdc++.h> using namespace std; const int N = 2009; int n, m, dn[N][N], P[N]; long long tot, sum, dp[N]; char A[N][N]; vector < int > Q[N]; int Find(int v) { return ((P[v] > 0) ? (P[v] = Find(P[v])) : v); } inline void Merge(int v, int u) { v = Find(v); u = Find(u); if (v == u) return ; sum -= dp[-P[v]]; sum -= dp[-P[u]]; P[v] += P[u]; P[u] = v; sum += dp[-P[v]]; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%s", &A[i][1]); for (int i = n; i; i--) for (int j = 1; j <= m; j++) { dn[i][j] = dn[i + 1][j]; if (A[i][j] == '#') dn[i][j] = i; else if (i == n) dn[i][j] = i + 1; } for (int i = 1; i < N; i++) for (int j = 1; j <= i; j++) dp[i] += (i - j + 1) * j; for (int i = 1; i <= n; i++) { sum = 0; memset(P, 0, sizeof(P)); for (int j = 1; j <= m; j++) Q[dn[i][j] - 1].push_back(j); for (int j = n; j >= i; j--) { for (int &id : Q[j]) { P[id] = -1; sum += dp[1]; if (P[id - 1]) Merge(id, id - 1); if (P[id + 1]) Merge(id, id + 1); } tot += 1ll * sum * (j - i + 1); } for (int j = 0; j <= n; j++) Q[j].clear(); } return !printf("%lld", tot); }

Compilation message (stderr)

strah.cpp: In function 'int main()':
strah.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
strah.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s", &A[i][1]);
         ~~~~~^~~~~~~~~~~~~~~~
#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...