Submission #879785

# Submission time Handle Problem Language Result Execution time Memory
879785 2023-11-28T06:12:25 Z abcvuitunggio Dungeons Game (IOI21_dungeons) C++17
Compilation error
0 ms 0 KB
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
const int sz=24;
struct B{
    int u=-1;
    long long mx=0,mn=0,sum=0;
}nxt[400001][sz][2];
B operator +(B a, B b){
    return {b.u,max(a.mx,b.mx-a.sum),min(a.mn,b.mn-a.sum),a.sum+b.sum};
}
vector <int> S,P;
void init(int n, vector <int> s, vector <int> p, vector <int> w, vector <int> l){
    S=s;
    P=p;
    for (int i=0;i<n;i++){
        nxt[i][0][0]={w[i],s[i],s[i],s[i]};
        nxt[i][0][1]={l[i],s[i],s[i],p[i]};
    }
    for (int j=1;j<sz;j++){
        for (int i=0;i<n;i++)
            for (int k=0;k<2;k++){
                if (nxt[i][j-1][k].u==-1)
                    continue;
                nxt[i][j][k]=nxt[i][j-1][k]+nxt[nxt[i][j-1][k].u][j-1][k];
            }
    }
}
long long simulate(int x, int Z){
    int b=0;
    long long z=Z;
    while (true){
        if (nxt[x][0][0].u==-1)
            return z;
        for (int i=sz-1;i>=0;i--)
            if (nxt[x][i][b].u!=-1)
                if ((b&&z<nxt[x][i][b].mn)||(!b&&z>=nxt[x][i][b].mx)){
                    z+=nxt[x][i][b].sum;
                    x=nxt[x][i][b].u;
                }

        b^=1;
    }
	return z;
}

Compilation message

Compilation timeout while compiling dungeons