답안 #51210

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51210 2018-06-17T08:45:35 Z BrunoPloumhans 과수원 (NOI14_orchard) C++14
25 / 25
219 ms 20652 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;

  int cost = 0;
  vector<vector<int>> sums(n, vector<int>(m, 0));
  for(int i = 0; i < n; ++i) {
    for(int j = 0; j < m; ++j) {
      int x;
      cin >> x;
      sums[i][j] = (x == 1 ? 1 : -1);
      if(x == 1) {
	++cost;
      }
      /*if(i > 0) sums[i][j] += sums[i-1][j];
      if(j > 0) sums[i][j] += sums[i][j-1];
      if(i > 0 && j > 0) sums[i][j] -= sums[i-1][j-1];*/
      if(i > 0) {
	sums[i][j] += sums[i-1][j];
      }
    }
  }


  int ma = 0;
  for(int i = 0; i < n; ++i) {
    for(int j = i; j < n; ++j) {
      int cumul = 0;
      for(int k = 0; k < m; ++k) {
	cumul += sums[j][k];
	if(i > 0) {
	   cumul -= sums[i-1][k];
	}
	ma = max(ma, cumul);
	if(cumul < 0) {
	  cumul = 0;
	}
      }
    }
  }
  cout << cost - ma << endl;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 3 ms 572 KB Output is correct
4 Correct 2 ms 688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1072 KB Output is correct
2 Correct 4 ms 1196 KB Output is correct
3 Correct 6 ms 1196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 16780 KB Output is correct
2 Correct 92 ms 18740 KB Output is correct
3 Correct 99 ms 20652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 20652 KB Output is correct
2 Correct 21 ms 20652 KB Output is correct
3 Correct 20 ms 20652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 20652 KB Output is correct
2 Correct 8 ms 20652 KB Output is correct
3 Correct 8 ms 20652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 20652 KB Output is correct
2 Correct 184 ms 20652 KB Output is correct
3 Correct 219 ms 20652 KB Output is correct