Submission #487667

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

using namespace std;
long long din[2][100005];
long long mini,v[100005];
int n,k,i,j;
int min1(int a,int b)
{
    if (a<b)
    {
        return a;
    }
    return b;
}
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=min1(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:22:15: warning: unused variable 'mini' [-Wunused-variable]
   22 |     long long mini=1e12,lim=min1(mxdr,mij);
      |               ^~~~
stove.cpp:32:11: warning: 'poz' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |     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 0 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 0 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 7 ms 332 KB Output is correct
12 Correct 79 ms 360 KB Output is correct
13 Correct 126 ms 356 KB Output is correct
14 Correct 169 ms 332 KB Output is correct
15 Correct 165 ms 352 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 0 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 7 ms 332 KB Output is correct
12 Correct 79 ms 360 KB Output is correct
13 Correct 126 ms 356 KB Output is correct
14 Correct 169 ms 332 KB Output is correct
15 Correct 165 ms 352 KB Output is correct
16 Correct 52 ms 2548 KB Output is correct
17 Correct 208 ms 2708 KB Output is correct
18 Execution timed out 1090 ms 2604 KB Time limit exceeded
19 Halted 0 ms 0 KB -