제출 #718884

#제출 시각아이디문제언어결과실행 시간메모리
718884pragmatist과수원 (NOI14_orchard)C++17
25 / 25
147 ms17864 KiB
#include <bits/stdc++.h>                     
  
#define ll long long 
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) (int)v.size()
#define x first
#define y second
#define nl "\n"
  
using namespace std;
  
const int N = (int)2e5 + 7;
const int M = (int)2e6 + 5e5 + 7;
const ll MOD = (ll)1e9;                    
const int inf = (int)1e9 + 7;
const int B = (int)390;
const ll INF = (ll)1e18 + 7;
  
pair<int, int> dir[] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
 
bool bit(int mask, int i) {
    return (mask >> i & 1);
}
  
int sum(int x, int y) {
    x += y;
    if(x >= MOD) x -= MOD;
    return x;
}
  
int mult(int x, int y) {
    return 1ll * x * y % MOD;
}    

int n, m;

void solve() {
	cin >> n >> m;
	int a[n + 1][m + 1], p[n + 1][m + 1];
	memset(a, 0, sizeof(a));
	memset(p, 0, sizeof(p));
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			cin >> a[i][j];
			p[i][j] = p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1] + a[i][j];
		}
	}
	int ans = inf, ones = p[n][m], zero = n * m - ones;
	for(int i = 1; i <= n; ++i) {
		for(int j = i; j <= n; ++j) {
			int cur = 0;
			for(int y = 1; y <= m; ++y) {
				int res = -2 * (p[j][y] - p[i - 1][y]) + y * (j - i + 1);
				ans = min(ans, res + cur);		
				cur = min(cur, -2 * (p[i - 1][y] - p[j][y]) - y * (j - i + 1));
			}
		}
	}
	cout << ans + ones;	 	
}       
 
  
signed main() {                   
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int test = 1;                       
    //cin >> test;
    for(int i = 1; i <= test; ++i) {
        //cout << "Case " << i << ":\n";
        solve();
    }
    return 0;
}                   
/*
possible causes of error :
* array  bounds
* int overflow
* special case (n == 1?)
* haven't clean something
* wrong N | M | inf | INF | MOD

* try to write brute force to find test
* don't waste time
* don't write bullshit
* solution is easy
*/

컴파일 시 표준 에러 (stderr) 메시지

orchard.cpp: In function 'void solve()':
orchard.cpp:50:33: warning: unused variable 'zero' [-Wunused-variable]
   50 |  int ans = inf, ones = p[n][m], zero = n * m - ones;
      |                                 ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...