답안 #155953

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
155953 2019-10-02T07:34:33 Z Minnakhmetov 과수원 (NOI14_orchard) C++14
25 / 25
185 ms 12152 KB
#include <bits/stdc++.h>
   
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
 
using namespace std;

const int INF = 1e9 + 5, N = 1e6 + 5;
int n, m;
int a[N];
vector<vector<int>> v;

int calc(int h) {
    int mn = 0, ans = INF;

    for (int i = 1; i <= m; i++) {
        ans = min(ans, mn + i * h - a[i] * 2);
        mn = min(mn, a[i] * 2 - i * h);
    }

    return ans;
}

int solve() {
    v.resize(n + 1, vector<int>(m + 1));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> v[i][j];
            v[i][j] += v[i - 1][j] + v[i][j - 1] - v[i - 1][j - 1];
        }
    }
    int ans = INF;
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j++) {
            for (int k = 1; k <= m; k++) {
                a[k] = v[j][k] - v[i - 1][k];
            }
            ans = min(ans, calc(j - i + 1) + v[n][m]);
        }
    }
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;

    cout << solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 296 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 12152 KB Output is correct
2 Correct 94 ms 12152 KB Output is correct
3 Correct 92 ms 12076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 2288 KB Output is correct
2 Correct 20 ms 2288 KB Output is correct
3 Correct 19 ms 2288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 8 ms 504 KB Output is correct
3 Correct 8 ms 524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 185 ms 4840 KB Output is correct
2 Correct 185 ms 4752 KB Output is correct
3 Correct 185 ms 4856 KB Output is correct