Submission #525029

#TimeUsernameProblemLanguageResultExecution timeMemory
525029LoboDungeons Game (IOI21_dungeons)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;

const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

#define maxn 55000

int N, P[maxn], L[maxn], S[maxn], W[maxn];
pair<int,int> nx[maxn][10][32];
vector<int> st;
int tp;

pair<int,int> nxt(int u, int qtd, int id) {
    int val = 0;
    for(int pt = 30; pt >= 0; pt--) {
        if(qtd >= (1<<pt)) {
            qtd-= (1<<pt);
            val+= nx[u][id][pt].sc;
            u = nx[u][id][pt].fr;
        }
    }

    return mp(u,val);
}

int simulate(int32_t x, int32_t z) {
    int zz = z;
    if(tp == 0) {
        int id = 0;
        while(zz >= st[id]) id++;
        id--;

        while(x != N) {
            // cout << x << " " << zz << " " << id << endl;

            for(int pt = 30; pt >= 0; pt--) {
                int v = nx[x][id][pt].fr;
                int w = nx[x][id][pt].sc;
                if(!(zz+w >= st[id+1] || v == N)) {
                    zz+= w;
                    x = v;
                }
            }
            //pula mais um         
            id++;
        }
    }
    else {
        while(x != N) {
            if(S[x] <= zz) {
                //ganhou
                zz+= S[x];
                x = W[x];
            }
            else {
                //perdeu
                zz+= P[x];
                x = L[x];
            }
        }
    }

    return zz;
}

void solve() {
    int n, q;
    vector<int> s,p,w,l;
    cin >> n >> q;
    for(int i = 0; i < n; i++) {
        int x; cin >> x;
        s.pb(x);
    }
    for(int i = 0; i < n; i++) {
        int x; cin >> x;
        p.pb(x);
    }
    for(int i = 0; i < n; i++) {
        int x; cin >> x;
        w.pb(x);
    }
    for(int i = 0; i < n; i++) {
        int x; cin >> x;
        l.pb(x);
    }

    N = n;
    st.pb(0);
    st.pb(inf);
    for(int i = 0; i < n; i++) {
        st.pb(s[i]);
    }
    sort(all(st));
    st.erase(unique(all(st)),st.end());

    if(st.size() <= 2) {
        tp = 0;
        for(int i = 0; i < st.size(); i++) {
            for(int j = 0; j < n; j++) {
                if(s[j] <= st[i]) {
                    nx[j][i][0] = mp(w[j],s[j]);
                }
                else {
                    nx[j][i][0] = mp(l[j],p[j]);
                }
            }

            for(int pt = 0; pt <= 30; pt++) {
                nx[n][i][pt].fr = n;
                nx[n][i][pt].sc = 0; 
            }
            for(int pt = 1; pt <= 30; pt++) {
                for(int j = 0; j < n; j++) {
                    nx[j][i][pt].fr = nx[nx[j][i][pt-1].fr][i][pt-1].fr;
                    nx[j][i][pt].sc = nx[j][i][pt-1].sc + nx[nx[j][i][pt-1].fr][i][pt-1].sc;
                }
            }
        }
    }
    else {
        tp = 1;
        for(int i = 0; i < n; i++) {
            S[i] = s[i];
            W[i] = w[i];
            L[i] = l[i];
            P[i] = p[i];
        }
    }

    while(q--) {
        int x, z;
        cin >> x >> z;
        cout << simulate(x,z) << endl;
    }

}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    freopen("in.in", "r", stdin);
    //freopen("out.out", "w", stdout);
    
    int tt = 1;
    // cin >> tt;
    while(tt--) solve();

}

Compilation message (stderr)

dungeons.cpp: In function 'void solve()':
dungeons.cpp:107:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |         for(int i = 0; i < st.size(); i++) {
      |                        ~~^~~~~~~~~~~
dungeons.cpp: In function 'int32_t main()':
dungeons.cpp:150:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  150 |     freopen("in.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccqgkelP.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc0Dsp7Q.o:dungeons.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccqgkelP.o: in function `main':
grader.cpp:(.text.startup+0x3bd): undefined reference to `init(int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status