Submission #1200303

#TimeUsernameProblemLanguageResultExecution timeMemory
120030312345678웜뱃 (IOI13_wombats)C++17
76 / 100
20093 ms149400 KiB
#include "wombats.h"
#include <bits/stdc++.h>

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

using namespace std;

const int nx=5e3+5, cx=2e2+5, kx=10;

int r, c, ver[nx][cx], qs[nx][cx], dp[2][cx][cx];

int dist(int row, int a, int b)
{
    if (b>=a) return ver[row][a]+qs[row][b]-qs[row][a];
    else return ver[row][a]+qs[row][a]-qs[row][b];
}

struct segtree
{
    struct matrix
    {
        int mat[cx][cx];
        void build(int rowl, int rowr)
        {
            // mat[i][j]=start at j, end at i
            for (int i=0; i<c; i++) for (int j=0; j<c; j++) dp[rowl%2][i][j]=dist(rowl, j, i); //cout<<"init "<<i<<' '<<j<<' '<<dp[rowl%2][i][j]<<'\n';
            for (int i=rowl+1; i<=rowr; i++) 
            {
                int current=i%2, previous=1-current;
                for (int j=0; j<c; j++) for (int k=0; k<c; k++) dp[current][j][k]=1e9;
                for (int j=0; j<c; j++) for (int k=0; k<c; k++) for (int l=0; l<c; l++) dp[current][k][j]=min(dp[current][k][j], dp[previous][l][j]+dist(i, l, k));
            }
            for (int i=0; i<c; i++) for (int j=0; j<c; j++) mat[i][j]=dp[rowr%2][i][j]; //cout<<"debug "<<rowl<<' '<<rowr<<' '<<i<<' '<<j<<' '<<dp[rowr%2][i][j]<<'\n';
        }
    } d[2000];
    void merge(int l, int r, int idx)
    {
        for (int i=0; i<c; i++) for (int j=0; j<c; j++) d[idx].mat[i][j]=1e9;
        for (int i=0; i<c; i++) for (int j=0; j<c; j++) for (int k=0; k<c; k++) d[idx].mat[i][j]=min(d[idx].mat[i][j], d[2*idx+1].mat[i][k]+d[2*idx].mat[k][j]);
    }
    void build(int l, int r, int i)
    {
        if (r-l+1<=kx) return d[i].build(l, r), void();
        int md=(l+r)/2;
        build(l, md, 2*i);
        build(md+1, r, 2*i+1);
        merge(l, r, i);
    }
    void update(int l, int r, int i, int idx)
    {
        if (idx<l||r<idx) return;
        if (r-l+1<=kx) return d[i].build(l, r), void();
        int md=(l+r)/2;
        update(l, md, 2*i, idx);
        update(md+1, r, 2*i+1, idx);
        merge(l, r, i);
    }
} s;

void init(int R, int C, int H[5000][200], int V[5000][200]) {
    r=R, c=C;
    for (int i=0; i<R-1; i++) for (int j=0; j<C; j++) ver[i+1][j]=V[i][j];
    for (int i=0; i<R; i++) for (int j=0; j<C-1; j++) qs[i][j+1]=H[i][j]+qs[i][j];
    s.build(1, r-1, 1);
}

void changeH(int P, int Q, int W) {
    int lst=qs[P][Q+1]-qs[P][Q];
    int delta=W-lst;
    for (int i=Q+1; i<c; i++) qs[P][i]+=delta;
    if (P>0) s.update(1, r-1, 1, P);
}

void changeV(int P, int Q, int W) {
    ver[P+1][Q]=W;
    s.update(1, r-1, 1, P+1);
}

int escape(int V1, int V2) {
    vector<int> tmp;
    int res=1e9;
    for (int i=0; i<c; i++) res=min(res, s.d[1].mat[V2][i]+dist(0, V1, i));
    return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...