Submission #856836

# Submission time Handle Problem Language Result Execution time Memory
856836 2023-10-04T17:14:08 Z andrei_boaca Dungeons Game (IOI21_dungeons) C++17
37 / 100
7000 ms 1913504 KB
#include "dungeons.h"
#include <vector>
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
typedef long long ll;
ll s[400005],p[400005],w[400005],l[400005],cost[400005],to[24][400005];
ll n;
int dp[24][400005][12];
ll suma[24][400005][12];
int who[24][400005][12];
ll smax=0;
void init(int N, std::vector<int> S, std::vector<int> P, std::vector<int> W, std::vector<int> L)
{
    n=N;
    for(int i=0;i<n;i++)
    {
        s[i]=S[i];
        smax=max(smax,s[i]*1LL);
        p[i]=P[i];
        w[i]=W[i];
        l[i]=L[i];
    }
    w[n]=n;
    for(int k=0;k<24;k++)
    {
        for(int i=0;i<n;i++)
        {
            if(s[i]<(1<<k))
            {
                to[k][i]=w[i];
                cost[i]=s[i];
            }
            else
            {
                to[k][i]=l[i];
                cost[i]=p[i];
            }
            suma[k][i][0]=cost[i];
            who[k][i][0]=to[k][i];
        }
        cost[n]=0;
        to[k][n]=n;
        who[k][n][0]=n;
        suma[k][n][0]=0;
        for(int j=1;j<12;j++)
        {
            for(int i=0;i<=n;i++)
            {
                ll sum=0;
                ll x=i;
                for(int c=1;c<=4;c++)
                {
                    sum+=suma[k][x][j-1];
                    x=who[k][x][j-1];
                }
                who[k][i][j]=x;
                suma[k][i][j]=sum;
            }
        }
        for(int i=0;i<=n;i++)
        {
            if(s[i]>=(1<<k))
                dp[k][i][0]=0-s[i];
            else
                dp[k][i][0]=-1e9;
        }
        for(int j=1;j<12;j++)
        {
            for(int i=0;i<=n;i++)
            {
                ll x=i;
                ll maxim=-1e9;
                ll sum=0;
                for(int c=1;c<=4;c++)
                {
                    maxim=max(maxim,min(0LL,dp[k][x][j-1]+sum));
                    sum+=suma[k][x][j-1];
                    x=who[k][x][j-1];
                }
                dp[k][i][j]=maxim;
            }
        }
    }
}

long long simulate(int x, int z)
{
    ll rez=z;
    int cnt=0;
    while(x!=n)
    {
        ll k=0;
        for(int i=0;i<24;i++)
            if((1<<i)<rez)
                k=i;
        for(int i=11;i>=0;i--)
        {
            while(x!=n&&rez+dp[k][x][i]<0)
            {
                rez+=suma[k][x][i];
                x=who[k][x][i];
            }
        }
        rez+=s[x];
        x=w[x];
    }
    return rez;
}

Compilation message

dungeons.cpp: In function 'long long int simulate(int, int)':
dungeons.cpp:90:9: warning: unused variable 'cnt' [-Wunused-variable]
   90 |     int cnt=0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 205404 KB Output is correct
2 Correct 20 ms 205592 KB Output is correct
3 Correct 28 ms 213944 KB Output is correct
4 Correct 294 ms 450416 KB Output is correct
5 Correct 28 ms 213844 KB Output is correct
6 Correct 303 ms 450404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 209752 KB Output is correct
2 Correct 3867 ms 1908288 KB Output is correct
3 Correct 3460 ms 1912440 KB Output is correct
4 Correct 3748 ms 1913476 KB Output is correct
5 Correct 4817 ms 1913504 KB Output is correct
6 Correct 3746 ms 1912940 KB Output is correct
7 Correct 3164 ms 1912204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 209744 KB Output is correct
2 Correct 361 ms 451796 KB Output is correct
3 Execution timed out 7006 ms 451840 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 209744 KB Output is correct
2 Correct 361 ms 451796 KB Output is correct
3 Execution timed out 7006 ms 451840 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 209744 KB Output is correct
2 Correct 361 ms 451796 KB Output is correct
3 Execution timed out 7006 ms 451840 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 209752 KB Output is correct
2 Correct 3867 ms 1908288 KB Output is correct
3 Correct 3460 ms 1912440 KB Output is correct
4 Correct 3748 ms 1913476 KB Output is correct
5 Correct 4817 ms 1913504 KB Output is correct
6 Correct 3746 ms 1912940 KB Output is correct
7 Correct 3164 ms 1912204 KB Output is correct
8 Correct 25 ms 209744 KB Output is correct
9 Correct 361 ms 451796 KB Output is correct
10 Execution timed out 7006 ms 451840 KB Time limit exceeded
11 Halted 0 ms 0 KB -