Submission #143247

# Submission time Handle Problem Language Result Execution time Memory
143247 2019-08-13T12:06:31 Z Bodo171 Wombats (IOI13_wombats) C++14
0 / 100
158 ms 46448 KB
#include "wombats.h"
#include <iostream>
#include <fstream>
using namespace std;
const int rmax=5001;
const int cmax=201;
const int buck=2;
int h[rmax][cmax],v[rmax][cmax],dp[rmax][cmax];
int opt[cmax][cmax];
int arb[4*(rmax/buck)][cmax][cmax];
int n,m,i,j,start,sgn,len,k;
void recalc(int nod,int st,int dr)
{
    for(start=0;start<m;start++)
    {
        for(i=0;i<m;i++)
            dp[st][i]=(1<<30);
        dp[st][start]=0;
        for(i=st;i<=dr;i++)
        {
            if(i>st)
               for(j=0;j<m;j++)
                  dp[i][j]=(dp[i-1][j]+v[i-1][j]);
            for(j=1;j<m;j++)
                dp[i][j]=min(dp[i][j],dp[i][j-1]+h[i][j-1]);
            for(j=m-2;j>=0;j--)
                dp[i][j]=min(dp[i][j],dp[i][j+1]+h[i][j]);
        }
        for(j=0;j<m;j++)
            arb[nod][start][j]=dp[dr][j];
    }
}
void mrg(int A[][cmax],int trans[],int st[][cmax],int dr[][cmax])
{
    for(i=0;i<m;i++)
      for(j=0;j<m;j++)
        A[i][j]=(1<<30);
    for(i=0;i<m;i++)
        for(j=0;j<m;j++)
        {
            if(st[i][j]+dr[j][i]+trans[j]<A[i][i])
               A[i][i]=st[i][j]+dr[j][i]+trans[j],opt[0][i]=j;
        }
    int l,r;
    for(sgn=-1;sgn<=1;sgn+=2)
        for(len=1;len<m;len++)
            for(i=0;i<m;i++)
                if(i+len*sgn>=0&&i+len*sgn<m)
        {
            l=opt[len-1][i+sgn];r=opt[len-1][i];
            if(l>r) swap(l,r);
            for(k=l;k<=r;k++)
            {
                if(st[i][k]+dr[k][i+len*sgn]+trans[k]<A[i][i+len*sgn])
                {
                    A[i][i+len*sgn]=st[i][k]+dr[k][i+len*sgn]+trans[k];
                    opt[len][i]=k;
                }
            }
        }
}
void update(int nod,int l,int r,int poz)
{
    if(l==r)
    {
        recalc(nod,poz*buck,min((poz+1)*buck-1,n-1));
        return;
    }
    int m=(l+r)/2;
    if(poz<=m) update(2*nod,l,m,poz);
    else update(2*nod+1,m+1,r,poz);
    mrg(arb[nod],v[(m+1)*buck-1],arb[2*nod],arb[2*nod+1]);
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
    n=R;m=C;
    for(i=0;i<R;i++)
        for(j=0;j<C-1;j++)
            h[i][j]=H[i][j];
    for(i=0;i<R-1;i++)
        for(j=0;j<C;j++)
            v[i][j]=V[i][j];
    for(int p=0;p<=n/buck;p++)
        update(1,0,n/buck,p);
}

void changeH(int P, int Q, int W) {
    h[P][Q]=W;
    update(1,0,n/buck,P/buck);
}
void changeV(int P, int Q, int W) {
    v[P][Q]=W;
    update(1,0,n/buck,P/buck);
}

int escape(int V1, int V2) {
    return arb[1][V1][V2];
}

Compilation message

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
  int res;
      ^~~
# Verdict Execution time Memory Grader output
1 Correct 44 ms 34680 KB Output is correct
2 Correct 34 ms 34552 KB Output is correct
3 Incorrect 104 ms 36216 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 149 ms 9040 KB Output is correct
2 Correct 120 ms 8956 KB Output is correct
3 Incorrect 158 ms 9100 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 47 ms 46328 KB Output is correct
2 Incorrect 47 ms 46448 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 149 ms 9140 KB Output is correct
2 Correct 118 ms 8964 KB Output is correct
3 Incorrect 154 ms 9336 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 150 ms 9048 KB Output is correct
2 Correct 118 ms 9156 KB Output is correct
3 Incorrect 153 ms 9336 KB Output isn't correct
4 Halted 0 ms 0 KB -