답안 #29462

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
29462 2017-07-19T11:49:43 Z samir_droubi 과수원 (NOI14_orchard) C++14
25 / 25
196 ms 16768 KB
#include <bits/stdc++.h>
using namespace std;
int b[3][1000005];
int a[155][5005];
int n,m;
void solve1()
{
    int c=0;
    int ans=(1e9);

    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
        {
            scanf("%d",&a[i][j]);

            if(a[i][j]==0) a[i][j]=1 ;
            else a[i][j]=-1,++c;

            a[i][j]+=a[i-1][j];
        }

    for(int i=1;i<=n;++i)
        for(int j=i;j<=n;++j)
        {
            int mx=0;
            int sm=0;
            for(int k=1;k<=m;++k)
            {
                sm+=a[j][k]-a[i-1][k];
                ans=min(ans,sm-mx);
                mx=max(mx,sm);
            }
        }
    printf("%d\n",c+ans);
}
void solve2()
{
    int c=0;
    int ans=(1e9);

    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)
        {
            scanf("%d",&b[i][j]);

            if(b[i][j]==0) b[i][j]=1 ;
            else b[i][j]=-1,++c;

            b[i][j]+=b[i-1][j];
        }

    for(int i=1;i<=n;++i)
        for(int j=i;j<=n;++j)
        {
            int mx=0;
            int sm=0;
            for(int k=1;k<=m;++k)
            {
                sm+=b[j][k]-b[i-1][k];
                ans=min(ans,sm-mx);
                mx=max(mx,sm);
            }
        }
    printf("%d\n",c+ans);
}
int main()
{
    scanf("%d%d",&n,&m);
    if(m<=5000)
        solve1();
    else
        solve2();
    return 0;
}

Compilation message

orchard.cpp: In function 'void solve1()':
orchard.cpp:14:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&a[i][j]);
                                 ^
orchard.cpp: In function 'void solve2()':
orchard.cpp:44:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&b[i][j]);
                                 ^
orchard.cpp: In function 'int main()':
orchard.cpp:68:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
                        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 16768 KB Output is correct
2 Correct 0 ms 16768 KB Output is correct
3 Correct 0 ms 16768 KB Output is correct
4 Correct 0 ms 16768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 16768 KB Output is correct
2 Correct 0 ms 16768 KB Output is correct
3 Correct 0 ms 16768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 16768 KB Output is correct
2 Correct 106 ms 16768 KB Output is correct
3 Correct 119 ms 16768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 16768 KB Output is correct
2 Correct 16 ms 16768 KB Output is correct
3 Correct 33 ms 16768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 16768 KB Output is correct
2 Correct 6 ms 16768 KB Output is correct
3 Correct 3 ms 16768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 196 ms 16768 KB Output is correct
2 Correct 186 ms 16768 KB Output is correct
3 Correct 166 ms 16768 KB Output is correct