Submission #1042004

#TimeUsernameProblemLanguageResultExecution timeMemory
1042004BlagojBob (COCI14_bob)C++17
120 / 120
73 ms37700 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define ll long long #define all(x) (x).begin(), (x).end() const int mxn = 1e3 + 100; ll a[mxn][mxn], h[mxn][mxn], c[mxn][mxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j]; h[i][j] = 1; if (a[i][j] == a[i - 1][j]) h[i][j] += h[i - 1][j]; } } stack<int> s; ll ans = 0; for (int i = 1; i <= n; i++) { while (s.size()) s.pop(); for (int j = 1; j <= m; j++) { if (a[i][j] == a[i][j - 1]) { while (s.size() && h[i][s.top()] > h[i][j]) s.pop(); c[i][j] = c[i][s.top()] + (j - s.top()) * h[i][j]; ans += c[i][j]; s.push(j); } else { c[i][j - 1] = 0; h[i][j - 1] = 0; c[i][j] = h[i][j]; ans += c[i][j]; s.push(j - 1); s.push(j); } } } 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...