# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
892150 | 2023-12-25T02:00:50 Z | vkvkvkvk | Bob (COCI14_bob) | C++17 | 87 ms | 14136 KB |
#include <bits/stdc++.h> #define file(task) if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } #define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i) #define FORD(i, a, b) for(int i = (a), _b = (b); i >= _b; --i) using namespace std; const int maxN = 1e3; int N, M; int a[maxN+5][maxN+5]; int f[maxN+5], dp[maxN+5]; void read_input() { cin >> N >> M; FOR(i, 1, N) FOR(j, 1, M) cin >> a[i][j]; } void solve() { stack<int> S; int ans = 0; FOR(i, 1, N) { while(!S.empty()) S.pop(); int p = 0, id; FOR(j, 1, M) { if(a[i][j] != a[i - 1][j]) f[j] = 0; ++f[j]; if(a[i][j] != a[i][j - 1]) { p = j - 1; dp[j - 1] = 0; while(!S.empty()) S.pop(); } while(!S.empty() && f[S.top()] >= f[j]) S.pop(); if(S.empty()) id = p; else id = S.top(); // cout << i << ' ' << j << ' ' << id << endl; dp[j] = dp[id] + (j - id) * f[j]; S.push(j); ans += dp[j]; } } cout << ans; } int main() { cin.tie(0)->sync_with_stdio(0); file("LAND"); read_input(); solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 3164 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 3420 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 3672 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 3676 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 74 ms | 10832 KB | Output is correct |
2 | Incorrect | 42 ms | 6228 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 87 ms | 14136 KB | Output is correct |
2 | Incorrect | 43 ms | 6300 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 81 ms | 13792 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 82 ms | 13904 KB | Output is correct |
2 | Incorrect | 42 ms | 6224 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |