Submission #1276962

#TimeUsernameProblemLanguageResultExecution timeMemory
1276962SnowRaven52Bob (COCI14_bob)C++20
120 / 120
78 ms576 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<int> pr(m, INT_MIN), cr(m), h(m, 0); long long ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cin >> cr[j]; for (int j = 0; j < m; j++) { if (i > 0 && cr[j] == pr[j]) h[j] = h[j] + 1; else h[j] = 1; } int j = 0; while (j < m) { int k = j + 1; while (k < m && cr[k] == cr[j]) k++; long long rs = 0; vector<pair<int, int>> st; for (int x = j; x < k; x++) { int c = 1; while (!st.empty() && st.back().first >= h[x]) { rs -= 1LL * st.back().first * st.back().second; c += st.back().second; st.pop_back(); } st.emplace_back(h[x], c); rs += 1LL * h[x] * c; ans += rs; } j = k; } pr.swap(cr); } 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...