답안 #124741

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
124741 2019-07-03T20:20:57 Z AdOjis485 과수원 (NOI14_orchard) C++14
12 / 25
1000 ms 23800 KB
//
//  main.cpp
//  orchard
//
//  Created by Ema Skottova on 03.07.19.
//  Copyright © 2019 AdOjis485. All rights reserved.
//

#include <iostream>
#include <vector>
#define int int64_t
using namespace std;

signed main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> ps(n + 1, vector<int> (m + 1));
    int sum = 0;
    for(int i = 0; i <= n; i ++){
        int row = 0;
        for(int j = 0; j <= m; j ++){
            if(i == 0 || j == 0){
                ps[i][j] = 0;
            }
            else{
                int x;
                cin >> x;
                ps[i][j] = x + row;
                if(i > 1){
                    ps[i][j] += ps[i - 1][j];
                }
                row += x;
                sum += x;
            }
        }
    }
    int mi = n * m;
    /*cout << "\n";
    for (auto a : ps) {for (auto i : a) cout << i << " "; cout << "\n";}
    cout << "\n";*/
    if(n == 1){
        for(int i = 1; i <= m; i ++){
            for(int j = 1; j <= i; j ++){
                int rect_area = i - j + 1;
                int ones_inside = ps[1][i] - ps[1][j - 1];
                int zeros_inside = rect_area - ones_inside;
                int outside_area = n * m - rect_area;
                int ones_outside = sum - ones_inside;
                int zeros_outside = outside_area - ones_outside;
                int zero_one = zeros_inside + ones_outside;
                int one_zero = ones_inside + zeros_outside;
                mi = min(mi, zero_one);
            }
        }
    }
    else{
        for(int i1 = 1; i1 <= n; i1 ++){
            for(int i2 = 1; i2 <= i1; i2 ++){
                for(int j1 = 1; j1 <= m; j1 ++){
                    for(int j2 = 1; j2 <= j1; j2 ++){
                        int rect_area = (i1 - i2 + 1) * (j1 - j2 + 1);
                        int ones_inside = ps[i1][j1] - ps[i1][j2 - 1] - ps[i2 - 1][j1] + ps[i2 - 1][j2 - 1];
                        int zeros_inside = rect_area - ones_inside;
                        int outside_area = n * m - rect_area;
                        int ones_outside = sum - ones_inside;
                        int zeros_outside = outside_area - ones_outside;
                        int zero_one = zeros_inside + ones_outside;
                        int one_zero = ones_inside + zeros_outside;
                        mi = min(mi, zero_one);
                    }
                }
            }
        }
    }
    cout << mi << '\n';
    return 0;
}

Compilation message

orchard.cpp: In function 'int main()':
orchard.cpp:51:21: warning: unused variable 'one_zero' [-Wunused-variable]
                 int one_zero = ones_inside + zeros_outside;
                     ^~~~~~~~
orchard.cpp:68:29: warning: unused variable 'one_zero' [-Wunused-variable]
                         int one_zero = ones_inside + zeros_outside;
                             ^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 632 KB Output is correct
2 Correct 155 ms 760 KB Output is correct
3 Correct 155 ms 744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1077 ms 23800 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1075 ms 3448 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 376 KB Output is correct
2 Correct 248 ms 544 KB Output is correct
3 Correct 250 ms 536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1078 ms 6264 KB Time limit exceeded
2 Halted 0 ms 0 KB -