Submission #1115092

# Submission time Handle Problem Language Result Execution time Memory
1115092 2024-11-20T03:36:03 Z duytuandao21 Bob (COCI14_bob) C++17
24 / 120
1000 ms 44308 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int N = 2e5 + 7;
typedef pair<int, int> pii;

int n, m;
int a[2000][2000], s[2000][2000];
int bit[2000][2000];

void update(int u, int v, int val) {
    for (int i = u; i <= n; i += (i & (-i)))
        for (int j = v; j <= m; j += (j & (-j))) bit[i][j] += val;
} 
int get(int u, int v) {
    int ans = 0;
    for (int i = u; i > 0; i -= (i & (-i)))
        for (int j = v; j > 0; j -= (j & (-j))) ans += bit[i][j];
    return ans;
}
int cal(int x, int y, int u, int v) {
    return get(u, v) - get(u, y - 1) - get(x - 1, v) + get(x - 1, y - 1);
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) 
        for (int j = 1; j <= m; j++) cin >> a[i][j];
    
    int res = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            for (int ki = i; ki <= n; ki++) {
                for (int kj = j; kj <= m; kj++) {
                    if (a[ki][kj] != a[i][j]) {
                        update(ki, kj, 1);
                    }
                    if (cal(i, j, ki, kj) == 0) res++;
                }
            }
            for (int ki = i; ki <= n; ki++) {
                for (int kj = j; kj <= m; kj++) {
                    if (a[ki][kj] != a[i][j]) update(ki, kj, -1);
                }
            }
        }
    }
    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 79 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1049 ms 19528 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1051 ms 19792 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1056 ms 20048 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1047 ms 19924 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1043 ms 41544 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 40372 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1058 ms 44308 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1014 ms 40520 KB Time limit exceeded
2 Halted 0 ms 0 KB -