답안 #705511

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
705511 2023-03-04T14:52:47 Z BidoTeima 과수원 (NOI14_orchard) C++17
25 / 25
129 ms 17896 KB
/*
ID: BidoTeima
LANG: C++11
TASK:
*/
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
void moo(string filename);
void ACPLS(string str = "")
{
    if(str=="NOF")return;
    if(str.size() && str != "IIOT")
        moo(str);
    else if(str != "IIOT"){
#ifndef ONLINE_JUDGE
        freopen("output.txt", "w", stdout);
        freopen("input.txt", "r", stdin);
#endif
    }
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
void moo(string fileName){
    freopen((fileName+".in").c_str(),"r",stdin);
    freopen((fileName+".out").c_str(),"w",stdout);
}
#define tc         \
    int tttttt/*,subtask*/;    \
    cin >> tttttt/* >> subtask*/; \
    while (tttttt--)/*end
*/

int main()
{ 
    ACPLS("IIOT");  
    int n,m;
    cin>>n>>m;
    int a[n+1][m+1]={0}; 
    int total = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            char ch;
            cin>>ch; 
            a[i][j]=ch-'0'; 
            total += a[i][j]; 
        } 
    } 
    int colsum[n + 1][m + 1]={0}; 
    for(int j = 1; j <= m; j++){
        for(int i = 1; i <= n; i++){
            colsum[i][j] = colsum[i - 1][j] + a[i][j];
        }
    }
    int ans = 1e9;
    for(int a = 1; a <= n; a++){
        for(int x = a; x <= n; x++){
            int mn = 0;
            int cursum = 0;
            for(int i = 1; i <= m; i++){
                cursum += colsum[x][i] - colsum[a - 1][i]; 
                ans = min(ans, total + i * (x - a + 1) - 2 * cursum + mn);
                mn = min(mn, 2 * cursum - i * (x - a + 1));
            }
        }
    }
    cout << ans << '\n';
}

Compilation message

orchard.cpp: In function 'void ACPLS(std::string)':
orchard.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
orchard.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
orchard.cpp: In function 'void moo(std::string)':
orchard.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     freopen((fileName+".in").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
orchard.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((fileName+".out").c_str(),"w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 17896 KB Output is correct
2 Correct 32 ms 17836 KB Output is correct
3 Correct 32 ms 17892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3028 KB Output is correct
2 Correct 7 ms 3020 KB Output is correct
3 Correct 6 ms 3012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 4 ms 448 KB Output is correct
3 Correct 5 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 7680 KB Output is correct
2 Correct 129 ms 7680 KB Output is correct
3 Correct 115 ms 7676 KB Output is correct