Submission #1016674

# Submission time Handle Problem Language Result Execution time Memory
1016674 2024-07-08T10:16:31 Z JakobZorz Dungeons Game (IOI21_dungeons) C++17
11 / 100
1610 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<int>>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));
        gain=vector<vector<ll>>(n+1,vector<ll>(pw));
        win=vector<vector<int>>(n+1,vector<int>(pw));
        for(int p=0;p<pw;p++)
            jmp[n][p]=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++){
                jmp[i][p]=jmp[jmp[i][p-1]][p-1];
                gain[i][p]=gain[i][p-1]+gain[jmp[i][p-1]][p-1];
                win[i][p]=max(0LL,min(1LL*win[i][p-1],1LL*win[jmp[i][p-1]][p-1]-gain[i][p-1]));
            }
        }
    }
    
    // simulate until it either reaches n-th node, wins, or strength>=thres
    pair<int,ll>simulate(int x,ll st){
        for(int p=pw;p>=0;p--){
            if(jmp[x][p]!=n&&(win[x][p]>st||win[x][p]==1e9)&&st+gain[x][p]<thres){
                st+=gain[x][p];
                x=jmp[x][p];
            }
        }
        //while(x!=n&&st<thres){
            if(st>=st1[x]){
                st+=st1[x];
                x=nxt1[x];
                //break;
            }else{
                st+=st2[x];
                x=nxt2[x];
            }
        //}
        return{x,st};
    }
};

Dungeon dun[30];

void init(int N,vector<int>s,vector<int>p,vector<int>w,vector<int>l){
    n=N;
    
    for(int pw=0;pw<30;pw++){
        dun[pw]=Dungeon(n);
        dun[pw].thres=2LL<<pw;
        dun[pw].pw=pw/2+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[29].thres=1e18;
    for(int pw=0;pw<30;pw++)
        dun[pw].setup();
}

ll simulate(int x,int z){
    ll st=z;
    
    for(int p=0;p<30;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 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 16 ms 16104 KB Output is correct
4 Correct 357 ms 397676 KB Output is correct
5 Correct 15 ms 16180 KB Output is correct
6 Correct 384 ms 397344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8280 KB Output is correct
2 Runtime error 1610 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8280 KB Output is correct
2 Correct 422 ms 397516 KB Output is correct
3 Incorrect 606 ms 397348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8280 KB Output is correct
2 Correct 422 ms 397516 KB Output is correct
3 Incorrect 606 ms 397348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8280 KB Output is correct
2 Correct 422 ms 397516 KB Output is correct
3 Incorrect 606 ms 397348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8280 KB Output is correct
2 Runtime error 1610 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -