답안 #518907

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
518907 2022-01-25T05:53:08 Z sudheerays123 과수원 (NOI14_orchard) C++17
12 / 25
1000 ms 150960 KB
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define tc ll test;cin >> test;while(test--)
#define vi vector<ll>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define INF 1e18
#define MOD 1000000007
#define ff first
#define ss second
#define in >>
#define out <<
#define space << " " <<
#define spacef << " "
#define fo(i,a,b) for(ll i = a; i <= b; i++)
#define rfo(i,a,b) for(ll i = a; i >= b; i--)
#define nextline out "\n"
#define print(x) for(auto i : x ) cout out i spacef
#define mmax(x,i) x = max(x,i)
#define mmin(x,i) x = min(x,i)
#define N 105

int main() {
    
    fast;

	ll n,m;
	cin in n in m;

	vector<vi> grid(n+5,vi(m+5));

	vector<vi> sum0(n+5,vi(m+5));
	vector<vi> sum1(n+5,vi(m+5));

	ll cnt1 = 0;

	fo(i,1,n){
		fo(j,1,m){
			cin in grid[i][j];

			if(grid[i][j]) cnt1++;
			sum0[i][j] = sum0[i][j-1]+sum0[i-1][j]-sum0[i-1][j-1] + (grid[i][j] == 0);
			sum1[i][j] = sum1[i][j-1]+sum1[i-1][j]-sum1[i-1][j-1] + grid[i][j];
		}
	}

	ll ans = INF;

	fo(i1,1,n){
		fo(j1,1,m){

			fo(i2,i1,n){
				fo(j2,j1,m){
					ll zero = sum0[i2][j2]-sum0[i2][j1-1]-sum0[i1-1][j2]+sum0[i1-1][j1-1];
					ll one = cnt1-(sum1[i2][j2]-sum1[i2][j1-1]-sum1[i1-1][j2]+sum1[i1-1][j1-1]);

					mmin(ans,zero+one);
				}
			}
		}
	}

	cout out ans;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 176 ms 2560 KB Output is correct
2 Correct 169 ms 2628 KB Output is correct
3 Correct 178 ms 2560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1068 ms 150960 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1061 ms 17852 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 580 KB Output is correct
2 Correct 209 ms 924 KB Output is correct
3 Correct 209 ms 964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1032 ms 19976 KB Time limit exceeded
2 Halted 0 ms 0 KB -