답안 #950688

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
950688 2024-03-20T15:10:43 Z Irate 과수원 (NOI14_orchard) C++17
25 / 25
133 ms 19996 KB
#include<cstdio>
#include<vector>
using namespace std;
int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    vector<vector<int>>grid(n + 1, vector<int>(m + 1));
    vector<vector<int>>pref(n + 1, vector<int>(m + 1));
    for(int i = 1;i <= n;++i){
        for(int j = 1;j <= m;++j){
            scanf("%d", &grid[i][j]);
            pref[i][j] = pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + grid[i][j];
        }
    }
    int res = 1e9, total = pref[n][m];
    for(int k = 1;k <= n;++k){
        for(int i = 1;i + k - 1 <= n;++i){
            int mn = -1;
            for(int j = 1;j <= m;++j){
                int sum = pref[i + k - 1][j] - pref[i - 1][j];
                res = min(res, j * k - 2 * sum + total + k + mn);
                mn = min(mn, 2 * sum - k * (j + 1));
            }
        }
    }
    printf("%d", res);
}

Compilation message

orchard.cpp: In function 'int main()':
orchard.cpp:6:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
orchard.cpp:11:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |             scanf("%d", &grid[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 19996 KB Output is correct
2 Correct 67 ms 19992 KB Output is correct
3 Correct 75 ms 19992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 3028 KB Output is correct
2 Correct 13 ms 3176 KB Output is correct
3 Correct 13 ms 3176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 4 ms 616 KB Output is correct
3 Correct 5 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 6332 KB Output is correct
2 Correct 133 ms 6336 KB Output is correct
3 Correct 133 ms 6236 KB Output is correct