Submission #519238

# Submission time Handle Problem Language Result Execution time Memory
519238 2022-01-26T05:22:52 Z sudheerays123 Orchard (NOI14_orchard) C++17
16 / 25
582 ms 198052 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,1,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;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 304 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3268 KB Output is correct
2 Correct 3 ms 3148 KB Output is correct
3 Correct 3 ms 3276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 198052 KB Output is correct
2 Correct 163 ms 197968 KB Output is correct
3 Correct 171 ms 197896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 23324 KB Output is correct
2 Correct 25 ms 23344 KB Output is correct
3 Correct 27 ms 23340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 560 KB Output is correct
2 Incorrect 16 ms 1092 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 582 ms 26100 KB Output isn't correct
2 Halted 0 ms 0 KB -