Submission #590817

# Submission time Handle Problem Language Result Execution time Memory
590817 2022-07-06T11:39:20 Z andrei_boaca Popeala (CEOI16_popeala) C++14
26 / 100
2000 ms 65904 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int dp[20005][55],rmq[55][16][20005],vals[20005],loga[20005];
int n,t,S;
int val[20005];
bool have[55][20005];
int nxt[55][20005],s[20005];
bool bad[55];
int mycost[55];
int getmin(int st,int dr,int k)
{
    int l=loga[dr-st+1];
    int rez=min(rmq[k][l][st],rmq[k][l][dr-(1<<l)+1]);
    return rez;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>t>>S;
    for(int i=1;i<=t;i++)
    {
        for(int j=0;j<=15;j++)
            if((1LL<<j)<=i)
                loga[i]=j;
    }
    for(int i=1;i<=t;i++)
    {
        cin>>val[i];
        s[i]=s[i-1]+val[i];
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=t;j++)
        {
            char c;
            cin>>c;
            have[i][j]=c-'0';
        }
    for(int i=1;i<=n;i++)
    {
        nxt[i][0]=0;
        for(int j=1;j<=t;j++)
        {
            nxt[i][j]=nxt[i][j-1];
            if(!have[i][j])
                nxt[i][j]=j;
        }
        /*for(int j=1;j<=t;j++)
            cout<<nxt[i][j]<<' ';
        cout<<'\n';*/
    }
    dp[0][0]=0;
    for(int i=1;i<=S;i++)
        dp[0][i]=2e9;
    for(int i=1;i<=t;i++)
        dp[i][0]=2e9;
    for(int k=0;k<=n;k++)
    {
        for(int i=0;i<=t;i++)
            vals[i]=dp[i][0]-k*s[i];
        for(int i=t;i>=0;i--)
        {
            rmq[k][0][i]=vals[i];
            for(int j=1;j<=15;j++)
            {
                int poz=i+(1LL<<(j-1))-1;
                if(poz>t)
                    break;
                rmq[k][j][i]=rmq[k][j-1][i];
                if(poz+1<=t)
                    rmq[k][j][i]=min(rmq[k][j][i],rmq[k][j-1][poz+1]);
            }
        }
    }
    for(int a=1;a<=S;a++)
    {
        for(int i=1;i<=t;i++)
        {
            dp[i][a]=2e9;
            /*for(int k=i-1;k>=0;k--)
                dp[i][j]=min(dp[i][j],dp[k][j-1]+cost[k+1][i]);*/
        }
        vector<int> mypoz;
        for(int i=1;i<=t;i++)
        {
            dp[i][a]=2e9;
            int cnt=n;
            mypoz.clear();
            for(int j=1;j<=n;j++)
                mypoz.push_back(nxt[j][i]);
            sort(mypoz.begin(),mypoz.end());
            reverse(mypoz.begin(),mypoz.end());
            int cur=i;
            for(int j=0;j<mypoz.size();j++)
            {
                int poz=mypoz[j];
                int st=poz;
                int dr=cur-1;
                if(st<=dr)
                {
                    int nr=getmin(st,dr,cnt)+cnt*s[i];
                    dp[i][a]=min(dp[i][a],nr);
                }
                cur=poz;
                cnt--;
            }
            int st=0;
            int dr=cur-1;
            if(st<=dr)
            {
                int nr=getmin(st,dr,cnt)+cnt*s[i];
                dp[i][a]=min(dp[i][a],nr);
            }
        }
        for(int k=0;k<=n;k++)
        {
            for(int i=0;i<=t;i++)
                vals[i]=dp[i][a]-k*s[i];
            for(int i=t;i>=0;i--)
            {
                rmq[k][0][i]=vals[i];
                for(int j=1;j<=15;j++)
                {
                    int poz=i+(1LL<<(j-1))-1;
                    if(poz>t)
                        break;
                    rmq[k][j][i]=rmq[k][j-1][i];
                    if(poz+1<=t)
                        rmq[k][j][i]=min(rmq[k][j][i],rmq[k][j-1][poz+1]);
                }
            }
        }
    }
    for(int i=1;i<=S;i++)
        cout<<dp[t][i]<<'\n';
    return 0;
}

Compilation message

popeala.cpp: In function 'int main()':
popeala.cpp:95:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |             for(int j=0;j<mypoz.size();j++)
      |                         ~^~~~~~~~~~~~~
popeala.cpp:26:23: warning: array subscript 32768 is above array bounds of 'int [20005]' [-Warray-bounds]
   26 |                 loga[i]=j;
      |                 ~~~~~~^
popeala.cpp:4:50: note: while referencing 'loga'
    4 | int dp[20005][55],rmq[55][16][20005],vals[20005],loga[20005];
      |                                                  ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 2 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 4052 KB Output is correct
2 Correct 54 ms 3904 KB Output is correct
3 Correct 59 ms 4052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 304 ms 9112 KB Output is correct
2 Correct 459 ms 11892 KB Output is correct
3 Correct 591 ms 14956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 2 ms 1748 KB Output is correct
3 Correct 65 ms 4052 KB Output is correct
4 Correct 54 ms 3904 KB Output is correct
5 Correct 59 ms 4052 KB Output is correct
6 Correct 304 ms 9112 KB Output is correct
7 Correct 459 ms 11892 KB Output is correct
8 Correct 591 ms 14956 KB Output is correct
9 Correct 903 ms 23284 KB Output is correct
10 Correct 1273 ms 30104 KB Output is correct
11 Execution timed out 2075 ms 65904 KB Time limit exceeded
12 Halted 0 ms 0 KB -