Submission #82304

# Submission time Handle Problem Language Result Execution time Memory
82304 2018-10-29T20:56:35 Z patcasrares Wiring (IOI17_wiring) C++14
0 / 100
311 ms 13188 KB
#include<iostream>
#include<fstream>
#include<vector>
#define pb push_back
#define x first
#define y second
using namespace std;
ifstream fin("t.in");
ofstream fout("t.out");
const int DN=2e5+5;
long long n,m,ml[2][DN],poz1,poz2,nr,poz,l,f,urm,pr[DN],dp[DN];
long long s[DN],st,dr,mij1,mij2,val1,val2,val;
pair<int,int>r[DN];
vector<int>a,b;
long long ve(int st,int l,int dr)
{
    long long val=dp[st-1],f=min(l-st+1,dr-l);
    val+=1LL*r[l+1].x*f;
    val-=s[st+f-1]-s[st-1];

    val+=s[l+f]-s[l];
    val-=1LL*r[l+1].x*f;

    val+=1LL*(l-st+1-f)*r[l+1].x;
    val-=s[l]-s[st+f-1];

    val+=s[dr]-s[l+f];
    val-=1LL*(dr-l-f)*r[l].x;
    return val;
}
long long min_total_length(vector<int>a,vector<int>b)
{
    n=a.size();
    m=b.size();
    poz1=poz2=0;
    nr=n+m;
    poz=-1;
    f=0;
    for(int i=0;i<=n+m;i++)
        dp[i]=1e16;
    while(nr--)
    {
        f++;
        urm=1e18;
        if(poz1==n)
        {
            r[f]={b[poz2],1};
            poz2++;
        }
        else
            if(poz2==m)
            {
                r[f]={a[poz1],0};
                poz1++;
            }
            else
                if(a[poz1]<b[poz2])
                {
                    r[f]={a[poz1],0};
                    poz1++;
                    urm=b[poz2];
                }
                else
                {
                    r[f]={b[poz2],1};
                    poz2++;
                    urm=a[poz1];
                }
        if(f==0)
            continue;
        if(r[f].y==r[f-1].y)
            pr[f]=pr[f-1];
        else
            pr[f]=f-1;
    }
    for(int i=1;i<=f;i++)
        s[i]=s[i-1]+r[i].x;
    dp[0]=0;
    for(int i=1;i<=f;i++)
    {
        if(pr[i]==0)
            continue;
        dr=pr[i];
        st=pr[pr[i]]+1;
        l=dr;
        while(dr-st>200)
        {
            mij1=st+(dr-st)/3;
            mij2=dr-(dr-st)/3;
            val1=ve(mij1,l,i);
            val2=ve(mij2,l,i);
            if(val1<val2)
                dr=mij2;
            else
                st=mij1;
        }
        val=1e16;
        for(int j=st;j<=dr;j++)
            val=min(val,ve(j,l,i));
        dp[i]=val;
    }
    return dp[f];
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 504 KB 3rd lines differ - on the 1st token, expected: '14340', found: '14694'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 616 KB Output is correct
2 Correct 2 ms 616 KB Output is correct
3 Incorrect 104 ms 7880 KB 3rd lines differ - on the 1st token, expected: '41596985758595', found: '10000000000000000'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7880 KB Output is correct
2 Correct 2 ms 7880 KB Output is correct
3 Incorrect 50 ms 11804 KB 3rd lines differ - on the 1st token, expected: '1068938599', found: '1152497305'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11804 KB Output is correct
2 Incorrect 311 ms 13188 KB 3rd lines differ - on the 1st token, expected: '373710605', found: '10000000000000000'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 504 KB 3rd lines differ - on the 1st token, expected: '14340', found: '14694'
3 Halted 0 ms 0 KB -