답안 #1113209

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1113209 2024-11-16T03:50:35 Z votranngocvy 과수원 (NOI14_orchard) C++14
8 / 25
1000 ms 26704 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N = 5e3 + 2;
int a[155][N],sum[N],pre[155][N],suf[N];
int n,m,total;

bool check(int mid) {
    for (int l = 1; l <= n; l++)
        for (int r = l; r <= n; r++) {
            sum[0] = 0;
            for (int i = 1; i <= m; i++)
                sum[i] = sum[i - 1] + pre[r][i] - pre[l - 1][i];
            suf[m + 1] = 1e18;
            for (int i = m; i > 0; i--)
                suf[i] = min(suf[i + 1],2 * sum[i] - (r - l + 1) * i);
            for (int i = 1; i <= m; i++)
                if (suf[i + 1] <= mid + 2 * sum[i - 1] - total - (r - l + 1) * (i - 1)) return 1;
        }
    return 0;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    total = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            char x;
            cin >> x;
            a[i][j] = x - '0';
            total += a[i][j];
            pre[i][j] = pre[i - 1][j] + 1 - a[i][j];
        }
    int l = 0,r = n * m,ans = -1;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (check(mid)) ans = mid,r = mid - 1;
        else l = mid + 1;
    }
    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 32 ms 26704 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 2640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1360 KB Output is correct
2 Correct 47 ms 1872 KB Output is correct
3 Correct 39 ms 1872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1065 ms 13648 KB Time limit exceeded
2 Halted 0 ms 0 KB -