이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
const int MAXN = 50005;
int n;
vector<int> s, p, w, l;
int nxt[25][25][MAXN];
lint cost[25][25][MAXN];
lint value[25][25][MAXN];
void init(int _n, std::vector<int> _s, std::vector<int> _p, std::vector<int> _w, std::vector<int> _l) {
tie(n, s, p, w, l) = make_tuple(_n, _s, _p, _w, _l);
s.resize(n + 1);
for(int i = 0; i < 25; i++){
int L = (1 << i), R = (2 << i);
for(int j = 0; j < n; j++){
if(s[j] < L){
nxt[i][0][j] = w[j];
cost[i][0][j] = s[j];
value[i][0][j] = 1e18;
}
else{
nxt[i][0][j] = l[j];
cost[i][0][j] = p[j];
value[i][0][j] = s[j];
}
}
nxt[i][0][n] = n;
cost[i][0][n] = 1e8;
value[i][0][n] = 1e18;
for(int j = 1; j < 25; j++){
for(int k = 0; k <= n; k++){
nxt[i][j][k] = nxt[i][j-1][nxt[i][j-1][k]];
cost[i][j][k] = cost[i][j-1][k] + cost[i][j-1][nxt[i][j-1][k]];
value[i][j][k] = min(value[i][j-1][k], value[i][j-1][nxt[i][j-1][k]] - cost[i][j-1][k]);
}
}
}
return;
}
long long simulate(int x, int zz) {
lint z = zz;
for(int i = 0; i < 25; i++){
if(z >= (1 << i) && z < (2 << i)){
/*
for(int j = 24; j >= 0; j--){
if(z + cost[i][j][x] < (2<<i) && value[i][j][x] > z){
z += cost[i][j][x];
x = nxt[i][j][x];
}
}
int step = 0;
while(z < (2 << i) && (s[x] > z || s[x] < (1 << i))){
step++;
z += cost[i][0][x];
x = nxt[i][0][x];
}
assert(step <= 1);*/
while(x != n && z < (2 << i) && value[i][0][x] > z){
z += cost[i][0][x];
x = nxt[i][0][x];
}
if(x == n){
// assert(z >= (2 << i));
// z -= int(1e8);
break;
}
if(s[x] <= z){
z += s[x];
x = w[x];
}
assert(z >= (2 << i));
if(x == n) break;
}
}/*
for(int i = 19; i >= 0; i--){
if(nxt[24][i][x] != n){
z += cost[24][i][x];
x = nxt[24][i][x];
}
}
*/
while(x != n){
z += s[x];
x = w[x];
}
assert(x == n);
return z;
}
컴파일 시 표준 에러 (stderr) 메시지
dungeons.cpp: In function 'void init(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
dungeons.cpp:20:21: warning: unused variable 'R' [-Wunused-variable]
20 | int L = (1 << i), R = (2 << i);
| ^| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |