Submission #457902

#TimeUsernameProblemLanguageResultExecution timeMemory
457902blueDungeons Game (IOI21_dungeons)C++17
Compilation error
0 ms0 KiB
#include "dungeons.h"
#include <vector>
#include <iostream>
#include <cassert>
using namespace std;

const int maxN = 300'000;
const int lgN = 20;
const int lgS = 25;
//
int N;
vector<int> S;
vector<int> P;
vector<int> W;
vector<int> L;
//
int nxt[maxN + 1][lgS][lgN]; //dungeon
long long gain[maxN + 1][lgS][lgN];
long long min_change[maxN + 1][lgS][lgN]; //minimum start to end up in different magnitude.

void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l)
{
    s.push_back(0);
    p.push_back(0);
    w.push_back(n);
    l.push_back(n);

    N = n;
    S = s;
    P = p;
    W = w;
    L = l;

    for(int i = 0; i <= N; i++)
    {
        for(int k = 0; k < lgS; k++)
        {
            if(s[i] < (1 << k))
            {
                nxt[i][k][0] = w[i];
                gain[i][k][0] = s[i];
                min_change[i][k][0] = (1 << (k+1)) - gain[i][k][0];
            }
            else if((1 << k) <= s[i] && s[i] < (1 << (k+1)))
            {
                nxt[i][k][0] = l[i];
                gain[i][k][0] = p[i];

                if(s[i] <= p[i])
                    min_change[i][k][0] = 0;
                else
                    min_change[i][k][0] = (1 << (k+1)) - s[i];

                //case 1: s[i] <= p[i]
                //min_change = 0

                //case 2: p[i] < s[i]
                //     if(z < p[i]), min_change = 0
                //     if(p[i] <= z < s[i]), min_change = 2^(k+1) - p[i]
                //     if(s[i] <= z), min_change = 2^(k+1) - s[i]
            }
            else
            {
                nxt[i][k][0] = l[i];
                gain[i][k][0] = p[i];
                min_change[i][k][0] = (1 << (k+1)) - gain[i][k][0];
            }
        }
    }

    for(int e = 1; e < lgN; e++)
    {
        for(int i = 0; i <= N; i++)
        {
            for(int k = 0; k < lgS; k++)
            {
                nxt[i][k][e] = nxt[ nxt[i][k][e-1] ][k][e-1];
                gain[i][k][e] = gain[i][k][e-1] + gain[ nxt[i][k][e-1] ][k][e-1];
                min_change[i][k][e] = min(min_change[i][k][e-1], min_change[ nxt[i][k][e-1] ][k][e-1] - gain[i][k][e-1]);
            }
        }
    }
}

long long simulate(int x, int z)
{
    int X = x;
    long long Z = z;
    for(int k = 0; k < lgS; k++)
    {
        cerr << "\n\n\n";
        cerr << "k = " << k << '\n';
        cerr << "X = " << X << '\n';
        cerr << "Z = " << Z << '\n';
        if((1 << (k+1)) <= Z) continue;
        cerr << "entered!\n";
        cerr << "Z = " << Z << '\n';
        for(int e = lgN - 1; e >= 0; e--)
        {
            cerr << X << ' ' << k << ' ' << e << ' ' << min_change[X][k][e] << ' ' << nxt[X][k][e] << ' ' << gain[X][k][e] << '\n';
            if(Z >= min_change[X][k][e]) continue;
            Z += gain[X][k][e];
            X = nxt[X][k][e];

            if(X == N) return Z;
        }
        cerr << "Z = " << Z << '\n';
        assert((1 << k) <= Z);
        assert(Z < (1 << (k+1)));


        if(Z >= S[X])
        {
            Z += S[X];
            X = W[X];
        }
        else
        {
            Z += P[X];
            X = L[X];
        }

        if(X == N) return Z;

        cerr << "after manual operation, Z = " << Z << '\n';
    }

    return Z;
}

Compilation message (stderr)

/tmp/ccIhQkSv.o: in function `main':
grader.cpp:(.text.startup+0x178): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x17f): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x19d): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x1a4): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x1b0): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x1b7): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x1c3): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x1ca): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x1d6): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x1dd): relocation truncated to fit: R_X86_64_PC32 against `.bss'
grader.cpp:(.text.startup+0x1e9): additional relocation overflows omitted from the output
/usr/bin/ld: failed to convert GOTPCREL relocation; relink with --no-relax
collect2: error: ld returned 1 exit status