Submission #375855

# Submission time Handle Problem Language Result Execution time Memory
375855 2021-03-10T05:24:12 Z daniel920712 Two Dishes (JOI19_dishes) C++14
0 / 100
220 ms 25536 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>

using namespace std;
long long all1[1000005],Time1[1000005],how1[1000005];
long long all2[1000005],Time2[1000005],how2[1000005];
long long pre1[1000005]={0};
long long pre2[1000005]={0};

long long score1[1000005]={0};
long long score2[1000005]={0};
bool have[2005][2005];
long long DP[2005][2005]={0};
long long N,M;
vector < pair < long long , pair < long long , long long > > > all;
long long F(long long x,long long y)
{
    long long a=0,b=0;
    if(x==N&&y==M) return 0;
    if(have[x][y]) return DP[x][y];
    have[x][y]=1;
    if(x==N)
    {
        DP[x][y]=F(x,y+1);
        if((pre1[x]+pre2[y+1])<=Time2[y]) DP[x][y]+=how2[y];
    }
    else if(y==M)
    {
        DP[x][y]=F(x+1,y);
        if((pre1[x+1]+pre2[y])<=Time1[x]) DP[x][y]+=how1[x];
    }
    else
    {
        a=F(x,y+1);
        if((pre1[x]+pre2[y+1])<=Time2[y]) a+=how2[y];
        b=F(x+1,y);
        if((pre1[x+1]+pre2[y])<=Time1[x]) b+=how1[x];
        DP[x][y]=max(a,b);
    }
    return DP[x][y];
}
int main()
{
    long long ans=-1e18,i,a,b;
    scanf("%lld %lld",&N,&M);
    for(i=0;i<N;i++)
    {
        scanf("%lld %lld %lld",&all1[i],&Time1[i],&how1[i]);
        pre1[i+1]=pre1[i]+all1[i];
        score1[i+1]=score1[i]+how1[i];
        all.push_back(make_pair(Time1[i],make_pair(0,i)));
    }
    for(i=0;i<M;i++)
    {
        scanf("%lld %lld %lld",&all2[i],&Time2[i],&how2[i]);
        pre2[i+1]=pre2[i]+all2[i];
        score2[i+1]=score2[i]+how2[i];
        all.push_back(make_pair(Time2[i],make_pair(1,i)));
    }
    sort(all.begin(),all.end());
    ans=0;
    a=0;
    b=0;
    for(auto i:all)
    {
        if(i.second.first==0)
        {
            if(pre1[i.second.first+1]+pre2[b]<=i.first)
            {
                ans++;
                a=i.second.first+1;
            }
        }
        else
        {
            if(pre1[a]+pre2[i.second.first+1]<=i.first)
            {
                ans++;
                b=i.second.first+1;
            }
        }
    }
    printf("%lld\n",ans);
    /*if(N<=2000&&M<=2000) printf("%lld\n",F(0,0));
    else
    {
        for(i=0;i<=N;i++)
        {
            if(pre1[i]<=Time1[0])
            {
                ans=max(ans,score1[i]+score2[upper_bound(pre2,pre2+M+1,Time1[0]-pre1[i])-pre2-1]);
            }
        }
        printf("%lld\n",ans);
    }*/
    return 0;
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |     scanf("%lld %lld",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
dishes.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |         scanf("%lld %lld %lld",&all1[i],&Time1[i],&how1[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   58 |         scanf("%lld %lld %lld",&all2[i],&Time2[i],&how2[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 220 ms 25536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 220 ms 25536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 220 ms 25536 KB Output isn't correct
2 Halted 0 ms 0 KB -