제출 #1046279

#제출 시각아이디문제언어결과실행 시간메모리
1046279VMaksimoski008던전 (IOI21_dungeons)C++17
24 / 100
7098 ms183112 KiB
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int maxn = 6e5 + 5;
const int LOG = 25;
vector<int> S, P, W, L;
ll N, sub3 = 1, up[maxn][LOG];
ll sum[maxn][LOG], dist[maxn];

void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) {
    N = n;
    S = s;
    P = p;
    W = w;
    L = l;

    for(int i=1; i<N; i++) if(S[i] != S[i-1]) sub3 = 0;
    for(int i=N-1; i>=0; i--) dist[i] = dist[W[i]] + S[i];
    for(int i=0; i<N; i++) up[i][0] = L[i], sum[i][0] = P[i];
    up[N][0] = N;

    for(int j=1; j<LOG; j++)
        for(int i=0; i<=N; i++) up[i][j] = up[up[i][j-1]][j-1];
    for(int j=1; j<LOG; j++)
        for(int i=0; i<=N; i++) sum[i][j] = sum[i][j-1] + sum[up[i][j-1]][j-1];
	return;
}

ll simulate(int x, int z) {
    if(sub3) {
        if(z >= S[x]) return (ll)z + dist[x];
        ll ans = z;

        for(int i=LOG-1; i>=0; i--) {
            if(ans + sum[x][i] < S[x]) {
                ans += sum[x][i];
                x = up[x][i];
            }
        }

        if(x == N) return ans;
        if(ans < S[x]) ans += P[x], x = up[x][0];
        return ans + dist[x];
    }

    ll ans = z;
    while(x != N) {
        if(z >= S[x]) {
            z += S[x];
            x = W[x];
        } else {
            z += P[x];
            x = L[x];
        }
    }
	return z;
}

컴파일 시 표준 에러 (stderr) 메시지

dungeons.cpp: In function 'void init(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
dungeons.cpp:26:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   26 |     for(int j=1; j<LOG; j++)
      |     ^~~
dungeons.cpp:28:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   28 |  return;
      |  ^~~~~~
dungeons.cpp: In function 'll simulate(int, int)':
dungeons.cpp:48:8: warning: unused variable 'ans' [-Wunused-variable]
   48 |     ll ans = z;
      |        ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...