답안 #55938

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
55938 2018-07-09T07:54:46 Z red1108 조개 줍기 (KOI17_shell) C++17
0 / 100
342 ms 46272 KB
#include <iostream>
#include <stdio.h>
using namespace std;
long long int dp[1600][1600], seg[1600][6000], input[1600][1600],ans;
long long int n, si=1;
long long  query(int x, int y)
{
    long long int ret=0;
    y=y+si-1;
    while(y)
    {
        ret+=seg[x][y];
        y/=2;
    }
    return ret;
}
void gang(int x, int v, int l, int r, int s, int e, int t)
{
    if(l>r||e<l||r<s)
        return ;
    if(s<=l&&r<=e)
    {
        seg[x][v]+=t;
        return ;
    }
    gang(x,v*2,l,(l+r)/2,s,e,t);
    gang(x,v*2+1,((l+r)/2)+1,r,s,e,t);
}
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    long long int i, j,k,inx,iny,s,e,d;
    char ina;
    scanf("%lld", &n);
    while(si<n)
        si*=2;
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=n; j++)
        {
            scanf("%lld", &input[i][j]);
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])+input[i][j];
            ans=ans+dp[i][j];
        }
    }
    printf("%lld\n", ans);
    for(k=1; k<=n; k++)
    {
        scanf("\n%c %lld %lld",&ina,&inx,&iny);
        if(ina=='U')
        {
            d=1;
            s=iny;
            for(i=iny+1; i<=n; i++)
            {
                if(max(dp[inx-1][i]+query(inx-1,i),dp[inx][i-1]+query(inx,i-1)+d)==dp[inx][i-1]+query(inx,i-1)+d)
                    continue;
                else
                    break;
            }
            e=i-1;
            gang(inx,1,1,si,s,e,d);
            ans=ans+(e-s+1)*d;
            for(i=inx+1; i<=n; i++)
            {
                while(max(dp[i-1][s]+query(i-1,s),dp[i][s-1]+query(i,s-1))==dp[i][s-1]+query(i,s-1))
                    s++;
                if(s>e)
                    break;
                for(j=e+1; j<=n; j++)
                {
                    if(max(dp[i-1][j]+query(i-1,j),dp[i][j-1]+query(i,j-1)+d)!=dp[i][j-1]+query(i,j-1)+d)
                        break;
                }
                e=j-1;
                if(s>e)
                    break;
                gang(i,1,1,si,s,e,d);
                ans=ans+(e-s+1)*d;
            }
        }
        else
        {
            d=-1;
            s=iny;
            for(i=iny+1; i<=n; i++)
            {
                if(dp[inx-1][i]+query(inx-1,i)<dp[inx][i-1]+query(inx,i-1)+d)
                    continue;
                else
                    break;
            }
            e=i-1;
            gang(inx,1,1,si,s,e,d);
            ans=ans+(e-s+1)*d;
            for(i=inx+1; i<=n; i++)
            {
                while(dp[i-1][s]+query(i-1,s)>dp[i][s-1]+query(i,s-1))
                    s++;
                if(s>e)
                    break;
                for(j=e+1; j<=n; j++)
                {
                    if(dp[i-1][j]+query(i-1,j)>=dp[i][j-1]+query(i,j-1)+d)
                        break;
                }
                e=j-1;
                if(s>e)
                    break;
                gang(i,1,1,si,s,e,d);
                ans=ans+(e-s+1)*d;
            }
        }
        printf("%lld\n", ans);
    }
}

Compilation message

shell.cpp: In function 'int main()':
shell.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &n);
     ~~~~~^~~~~~~~~~~~
shell.cpp:42:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld", &input[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
shell.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("\n%c %lld %lld",&ina,&inx,&iny);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 1912 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 342 ms 46272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 1912 KB Output isn't correct
2 Halted 0 ms 0 KB -