Submission #1016753

# Submission time Handle Problem Language Result Execution time Memory
1016753 2024-07-08T11:41:12 Z JakobZorz Dungeons Game (IOI21_dungeons) C++17
63 / 100
3279 ms 2097152 KB
#include"dungeons.h"
#include<vector>
#include<iostream>
typedef long long ll;
using namespace std;
 
int n;
 
struct Dungeon{
    vector<int>nxt1; // win
    vector<int>nxt2; // lose
    vector<ll>st1;  // strength
    vector<ll>st2;  // gain on losing
    vector<vector<int>>jmp; // where to jump?
    vector<vector<ll>>gain; // strength gain of that jump
    vector<vector<ll>>win;  // strength requirement to win in that jump
    int pw;
    ll thres=0;
    
    Dungeon(int n):nxt1(n),nxt2(n),st1(n),st2(n){}
    Dungeon()=default;
    
    void setup(){
        jmp=vector<vector<int>>(n+1,vector<int>((pw+1)/2));
        gain=vector<vector<ll>>(n+1,vector<ll>((pw+1)/2));
        win=vector<vector<ll>>(n+1,vector<ll>((pw+1)/2));
        for(int p=0;p<pw;p++)
            jmp[n][p/2]=n;
        
        for(int i=0;i<n;i++){
            jmp[i][0]=nxt2[i];
            gain[i][0]=st2[i];
            win[i][0]=st1[i];
        }
            
        for(int p=1;p<pw;p++){
            for(int i=0;i<n;i++){
                gain[i][p/2]=gain[i][(p-1)/2]+gain[jmp[i][(p-1)/2]][(p-1)/2];
                if(win[jmp[i][(p-1)/2]][(p-1)/2]==1e9)
                    win[i][p/2]=win[i][(p-1)/2];
                else
                    win[i][p/2]=max(0LL,min(1LL*win[i][(p-1)/2],1LL*win[jmp[i][(p-1)/2]][(p-1)/2]-gain[i][(p-1)/2]));
            }
            
            for(int i=0;i<n;i++)
                jmp[i][p/2]=jmp[jmp[i][(p-1)/2]][(p-1)/2];
        }
    }
    
    // simulate until it either reaches n-th node, wins, or strength>=thres
    pair<int,ll>simulate(int x,ll st){
        for(int p=pw-1;p>=0;p--){
            while(jmp[x][p/2]!=n&&(1LL*win[x][p/2]>st||win[x][p/2]==1e9)&&st+gain[x][p/2]<thres){
                st+=gain[x][p/2];
                x=jmp[x][p/2];
            }
        }
        while(x!=n&&st<thres){
            // do 1 more jump
            if(st>=st1[x]&&st1[x]!=1e9){
                st+=st1[x];
                x=nxt1[x];
                break;
            }else{
                st+=st2[x];
                x=nxt2[x];
            }
        }
        return{x,st};
    }
};
 
Dungeon dun[25];
 
void init(int N,vector<int>s,vector<int>p,vector<int>w,vector<int>l){
    n=N;
    
    for(int pw=0;pw<25;pw++){
        dun[pw]=Dungeon(n);
        dun[pw].thres=2LL<<pw;
        dun[pw].pw=pw+1;
        for(int i=0;i<n;i++){
            if(s[i]<=1<<pw){
                dun[pw].nxt1[i]=0;
                dun[pw].nxt2[i]=w[i];
                dun[pw].st1[i]=1e9;
                dun[pw].st2[i]=s[i];
            }else if(s[i]>=2<<pw){
                dun[pw].nxt1[i]=0;
                dun[pw].nxt2[i]=l[i];
                dun[pw].st1[i]=1e9;
                dun[pw].st2[i]=p[i];
            }else{
                dun[pw].nxt1[i]=w[i];
                dun[pw].nxt2[i]=l[i];
                dun[pw].st1[i]=s[i];
                dun[pw].st2[i]=p[i];
            }
        }
    }
    dun[24].thres=1e18;
    for(int pw=0;pw<25;pw++)
        dun[pw].setup();
}
 
ll simulate(int x,int z){
    ll st=z;
    
    for(int p=0;p<25;p++){
        while(x!=n&&st<2LL<<p){
            auto r=dun[p].simulate(x,st);
            x=r.first;
            st=r.second;
        }
    }
    
    return st;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 14 ms 13916 KB Output is correct
4 Correct 368 ms 338408 KB Output is correct
5 Correct 15 ms 13916 KB Output is correct
6 Correct 379 ms 338036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7004 KB Output is correct
2 Runtime error 2201 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7004 KB Output is correct
2 Correct 431 ms 337884 KB Output is correct
3 Correct 434 ms 338000 KB Output is correct
4 Correct 433 ms 337916 KB Output is correct
5 Correct 431 ms 337744 KB Output is correct
6 Correct 694 ms 337752 KB Output is correct
7 Correct 629 ms 339028 KB Output is correct
8 Correct 1081 ms 338812 KB Output is correct
9 Correct 415 ms 338768 KB Output is correct
10 Correct 996 ms 338768 KB Output is correct
11 Correct 932 ms 339168 KB Output is correct
12 Correct 3245 ms 339268 KB Output is correct
13 Correct 3279 ms 338984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7004 KB Output is correct
2 Correct 431 ms 337884 KB Output is correct
3 Correct 434 ms 338000 KB Output is correct
4 Correct 433 ms 337916 KB Output is correct
5 Correct 431 ms 337744 KB Output is correct
6 Correct 694 ms 337752 KB Output is correct
7 Correct 629 ms 339028 KB Output is correct
8 Correct 1081 ms 338812 KB Output is correct
9 Correct 415 ms 338768 KB Output is correct
10 Correct 996 ms 338768 KB Output is correct
11 Correct 932 ms 339168 KB Output is correct
12 Correct 3245 ms 339268 KB Output is correct
13 Correct 3279 ms 338984 KB Output is correct
14 Correct 8 ms 7004 KB Output is correct
15 Correct 419 ms 339284 KB Output is correct
16 Correct 441 ms 339376 KB Output is correct
17 Correct 530 ms 338944 KB Output is correct
18 Correct 565 ms 339284 KB Output is correct
19 Correct 663 ms 339140 KB Output is correct
20 Correct 739 ms 338892 KB Output is correct
21 Correct 919 ms 339028 KB Output is correct
22 Correct 1029 ms 339028 KB Output is correct
23 Correct 1597 ms 339044 KB Output is correct
24 Correct 1933 ms 339188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7004 KB Output is correct
2 Correct 431 ms 337884 KB Output is correct
3 Correct 434 ms 338000 KB Output is correct
4 Correct 433 ms 337916 KB Output is correct
5 Correct 431 ms 337744 KB Output is correct
6 Correct 694 ms 337752 KB Output is correct
7 Correct 629 ms 339028 KB Output is correct
8 Correct 1081 ms 338812 KB Output is correct
9 Correct 415 ms 338768 KB Output is correct
10 Correct 996 ms 338768 KB Output is correct
11 Correct 932 ms 339168 KB Output is correct
12 Correct 3245 ms 339268 KB Output is correct
13 Correct 3279 ms 338984 KB Output is correct
14 Correct 8 ms 7004 KB Output is correct
15 Correct 419 ms 339284 KB Output is correct
16 Correct 441 ms 339376 KB Output is correct
17 Correct 530 ms 338944 KB Output is correct
18 Correct 565 ms 339284 KB Output is correct
19 Correct 663 ms 339140 KB Output is correct
20 Correct 739 ms 338892 KB Output is correct
21 Correct 919 ms 339028 KB Output is correct
22 Correct 1029 ms 339028 KB Output is correct
23 Correct 1597 ms 339044 KB Output is correct
24 Correct 1933 ms 339188 KB Output is correct
25 Correct 396 ms 338260 KB Output is correct
26 Correct 516 ms 339444 KB Output is correct
27 Correct 426 ms 339008 KB Output is correct
28 Correct 409 ms 338968 KB Output is correct
29 Correct 565 ms 339284 KB Output is correct
30 Correct 871 ms 339128 KB Output is correct
31 Correct 1113 ms 338924 KB Output is correct
32 Correct 1138 ms 339024 KB Output is correct
33 Correct 641 ms 339028 KB Output is correct
34 Correct 1389 ms 338720 KB Output is correct
35 Correct 1022 ms 339048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7004 KB Output is correct
2 Runtime error 2201 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -