Submission #487666

# Submission time Handle Problem Language Result Execution time Memory
487666 2021-11-16T10:56:54 Z stefantaga Stove (JOI18_stove) C++14
50 / 100
1000 ms 3588 KB
#include <bits/stdc++.h>

using namespace std;
long long din[2][100005];
long long mini,v[100005];
int n,k,i,j;
void divide(int st,int dr,int mxst,int mxdr,int acum,int inainte)
{
    if (st>dr)
    {
        return;
    }
    int mij=(st+dr)/2,poz;
    long long mini=1e12,lim=min(mxdr,mij);
    din[acum][mij]=1e12;
    for (int i=mxst;i<=lim;i++)
    {
        if (v[mij]-v[i]+1+din[inainte][i-1]<din[acum][mij])
        {
            din[acum][mij]=v[mij]-v[i]+1+din[inainte][i-1];
            poz=i;
        }
    }
    divide(st,mij-1,mxst,poz,acum,inainte);
    divide(mij+1,dr,poz,mxdr,acum,inainte);
}
int main()
{
    #ifdef HOME
    ifstream cin("date.in");
    ofstream cout("date.out");
    #endif // HOME
    cin>>n>>k;
    for (i=1;i<=n;i++)
    {
        cin>>v[i];
        din[1][i]=v[i]-v[1]+1;
    }
    for (i=2;i<=k;i++)
    {
        int acum,inainte;
        acum=i%2;
        inainte=1-acum;
        divide(1,n,1,n,acum,inainte);
    }
    cout<<din[k%2][n];
    return 0;
}

Compilation message

stove.cpp: In function 'void divide(int, int, int, int, int, int)':
stove.cpp:14:15: warning: unused variable 'mini' [-Wunused-variable]
   14 |     long long mini=1e12,lim=min(mxdr,mij);
      |               ^~~~
stove.cpp:24:11: warning: 'poz' may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |     divide(st,mij-1,mxst,poz,acum,inainte);
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 9 ms 332 KB Output is correct
12 Correct 83 ms 344 KB Output is correct
13 Correct 150 ms 356 KB Output is correct
14 Correct 174 ms 368 KB Output is correct
15 Correct 189 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 9 ms 332 KB Output is correct
12 Correct 83 ms 344 KB Output is correct
13 Correct 150 ms 356 KB Output is correct
14 Correct 174 ms 368 KB Output is correct
15 Correct 189 ms 332 KB Output is correct
16 Correct 58 ms 2620 KB Output is correct
17 Correct 361 ms 3588 KB Output is correct
18 Execution timed out 1077 ms 3468 KB Time limit exceeded
19 Halted 0 ms 0 KB -