제출 #662937

#제출 시각아이디문제언어결과실행 시간메모리
662937winterfrost과수원 (NOI14_orchard)C++17
12 / 25
1085 ms19816 KiB
// Author: winterfrost (TLX account: Todoroki_Shouto) // Contest: Singapore National Olympiad in Informatics 2014 // Problem: A. Orchard # include <bits/stdc++.h> using namespace std; # define GRIND ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int main() { GRIND // For subtasks with small constraints int n, m; cin >> n >> m; char tree[n + 1][m + 1]; int alex = 0, bert = 0; int prefAlex[n + 1][m + 1]; int prefBert[n + 1][m + 1]; memset(prefAlex, 0, sizeof(prefAlex)); memset(prefBert, 0, sizeof(prefBert)); for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { cin >> tree[i][j]; if(tree[i][j] == '0') alex++; else bert++; prefAlex[i][j] = prefAlex[i - 1][j] + prefAlex[i][j - 1] - prefAlex[i - 1][j - 1] + (tree[i][j] == '0' ? 1 : 0); prefBert[i][j] = prefBert[i - 1][j] + prefBert[i][j - 1] - prefBert[i - 1][j - 1] + (tree[i][j] == '1' ? 1 : 0); } } int ans = INT_MAX; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { for(int k = i; k <= n; k++) { for(int l = j; l <= m; l++) { int apples = prefAlex[k][l] - prefAlex[i - 1][l] - prefAlex[k][j - 1] + prefAlex[i - 1][j - 1]; int bananas = prefBert[k][l] - prefBert[i - 1][l] - prefBert[k][j - 1] + prefBert[i - 1][j - 1]; int cost = (bert - bananas) + apples; ans = min(ans, cost); } } } } cout << ans << endl; return 0; }
#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...