이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
using namespace std;
#pragma GCC optimize("Ofast")
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <map>
typedef long long LL;
typedef pair<int,int> pii;
#define F first
#define S second
#define pb push_back
#define mkp make_pair
#define iter(x) x.begin() x.end()
#define REP(n) for (int __=n;__--;)
#define REP0(i,n) for (int i=0;i<n;++i)
#define REP1(i,n) for (int i=1;i<=n;++i)
const int maxn = 5e4+200,mod = 0;
const LL inf = 0;
pair <int,LL> lose[maxn][24];
int win[maxn][24],wrq;
int N;
void init(int n,vector <int> s,vector <int> p,vector <int> w,vector <int> l){
wrq = s[0];
N = n;
REP0(i,24){
win[n][i] = n;
lose[n][i] = mkp(n,0);
}
REP0(i,n){
win[i][0] = w[i];
lose[i][0] = mkp(l[i],p[i]);
}
REP1(j,23){
REP0(i,n){
win[i][j] = win[win[i][j-1]][j-1];
lose[i][j] = mkp(lose[lose[i][j-1].F][j-1].F,lose[i][j-1].S + lose[lose[i][j-1].F][j-1].S);
}
}
}
LL simulate(int x,int is){
LL z = is;
if (z < wrq){
for (int i=24;i--;){
if (z + lose[x][i].S < wrq and lose[x][i].F != N){
z += lose[x][i].S;
x = lose[x][i].F;
}
}
z += lose[x][0].S;
x = lose[x][0].F;
}
if (x == N) return z;
int s = 0;
for (int i=24;i--;){
if (win[x][i] != N){
x = win[x][i];
s |= (1 << i);
}
}
return z + (LL)wrq * (s+1);
}
# | 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... |