답안 #519239

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
519239 2022-01-26T05:25:51 Z sudheerays123 과수원 (NOI14_orchard) C++17
25 / 25
321 ms 196096 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,0));
	vector<vi> sum(n+5,vi(m+5,0));
	vector<vi> sum0(n+5,vi(m+5,0));
	vector<vi> sum1(n+5,vi(m+5,0));
	ll cnt = 0;

	fo(i,1,n){
		fo(j,1,m){

			cin in grid[i][j];

			if(!grid[i][j]) grid[i][j] = -1;
			else cnt++;
			
			sum0[i][j] = sum0[i-1][j]+sum0[i][j-1]-sum0[i-1][j-1]+(grid[i][j] == -1);
			sum1[i][j] = sum1[i-1][j]+sum1[i][j-1]-sum1[i-1][j-1]+(grid[i][j] == 1);
			sum[i][j] = sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+grid[i][j];
		}
	}

	ll ans = INF;

	fo(r1,1,n){
		fo(r2,r1,n){
			
			ll left = 1;

			for(ll right = 1; right <= m;){
				ll s = sum[r2][right]-sum[r2][left-1]-sum[r1-1][right]+sum[r1-1][left-1];
				ll one = cnt-(sum1[r2][right]-sum1[r2][left-1]-sum1[r1-1][right]+sum1[r1-1][left-1]);
				ll zero = sum0[r2][right]-sum0[r2][left-1]-sum0[r1-1][right]+sum0[r1-1][left-1];

				mmin(ans,one+zero);

				if(s < 0) left = right+1;
				right++;
			}
		}
	}

	cout out ans;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3276 KB Output is correct
2 Correct 2 ms 3276 KB Output is correct
3 Correct 3 ms 3276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 152 ms 195976 KB Output is correct
2 Correct 147 ms 195952 KB Output is correct
3 Correct 158 ms 196096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 22964 KB Output is correct
2 Correct 29 ms 23032 KB Output is correct
3 Correct 23 ms 22956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 588 KB Output is correct
2 Correct 10 ms 972 KB Output is correct
3 Correct 9 ms 1068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 321 ms 24652 KB Output is correct
2 Correct 313 ms 26108 KB Output is correct
3 Correct 314 ms 26116 KB Output is correct