이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <bits/stdc++.h>
#include <bits/extc++.h>
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define ef(a) emplace_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define tomax(a, b) ((a) = max((a), (b)))
#define tomin(a, b) ((a) = min((a), (b)))
#define topos(a) ((a) = (((a) % MOD + MOD) % MOD))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
if(pvaspace) b << " "; pvaspace=true;\
b << pva;\
}\
b << "\n";}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;
const ll MOD = 1000000007;
const ll MAX = 2147483647;
template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
return o << '(' << p.F << ',' << p.S << ')';
}
ll ifloor(ll a, ll b){
if(b < 0) a *= -1, b *= -1;
if(a < 0) return (a - b + 1) / b;
else return a / b;
}
ll iceil(ll a, ll b){
if(b < 0) a *= -1, b *= -1;
if(a > 0) return (a + b - 1) / b;
else return a / b;
}
struct info{
int go = 0;
ll add = 0;
int mn = MAX;
};
int n;
vector<int> s, p, w, l;
vector<vector<vector<info>>> dp;
int SZ = 25;
int SZ2 = 7;
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;
s.eb(0);
p.eb(0);
w.eb(n);
l.eb(n);
dp.resize(SZ2, vector<vector<info>>(SZ, vector<info>(n + 1)));
for(int i = 0; i < SZ2; i++){
for(int k = 0; k <= n; k++){
if(s[k] < (1 << (4 * i))){
dp[i][0][k].go = w[k];
dp[i][0][k].add = s[k];
}
else{
dp[i][0][k].go = l[k];
dp[i][0][k].add = p[k];
dp[i][0][k].mn = s[k];
}
}
}
for(int i = 0; i < SZ2; i++){
for(int j = 1; j < SZ; j++){
for(int k = 0; k <= n; k++){
dp[i][j][k].go = dp[i][j - 1][dp[i][j - 1][k].go].go;
dp[i][j][k].add = dp[i][j - 1][k].add + dp[i][j - 1][dp[i][j - 1][k].go].add;
ll tmp = dp[i][j - 1][dp[i][j - 1][k].go].mn;
if(tmp < MAX) tmp -= dp[i][j - 1][k].add;
dp[i][j][k].mn = min(dp[i][j - 1][k].mn, (int)max(0LL, tmp));
}
}
}
}
ll simulate(int x, int _z){
ll z = _z;
// cerr << "query " << x << " " << z << "\n";
while(x != n){
// cerr << "test " << x << " " << z << "\n";
int lg = min(SZ2 - 1, (int)__lg(z) / 4);
for(int i = SZ - 1; i >= 0; i--){
if(dp[lg][i][x].mn < MAX && dp[lg][i][x].mn <= z) continue;
z += dp[lg][i][x].add;
x = dp[lg][i][x].go;
}
z += s[x];
x = w[x];
// cerr << "ok " << x << " " << z << "\n";
}
return z;
}
# | 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... |