Submission #967566

# Submission time Handle Problem Language Result Execution time Memory
967566 2024-04-22T12:46:19 Z njoop Bob (COCI14_bob) C++14
120 / 120
551 ms 14416 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int n, m, arr[1010][1010], pref[2][1010][1010], w, h, mxh;
ll ans;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=m; j++) {
            cin >> arr[i][j];
        }
    }
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=m; j++) {
            if(arr[i][j] == arr[i][j-1]) {
                pref[0][i][j] = pref[0][i][j-1] + 1;
            } else {
                pref[0][i][j] = 1;
            }
        }
    }
    for(int j=1; j<=m; j++) {
        for(int i=1; i<=n; i++) {
            if(arr[i][j] == arr[i-1][j]) {
                pref[1][i][j] = pref[1][i-1][j] + 1;
            } else {
                pref[1][i][j] = 1;
            }
        }
    }
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=m; j++) {
            w = pref[0][i][j];
            h = pref[1][i][j];
            ans += h;
            for(int k=j-1; k>j-w; k--) {
                h = min(h, pref[1][i][k]);
                ans += h;
            }
        }
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 10844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 10840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 10840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 10712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 12372 KB Output is correct
2 Correct 498 ms 14340 KB Output is correct
3 Correct 551 ms 14348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 12372 KB Output is correct
2 Correct 227 ms 14340 KB Output is correct
3 Correct 547 ms 14332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 149 ms 12388 KB Output is correct
2 Correct 548 ms 14416 KB Output is correct
3 Correct 546 ms 14336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 12372 KB Output is correct
2 Correct 531 ms 14160 KB Output is correct
3 Correct 547 ms 14320 KB Output is correct