이 제출은 이전 버전의 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 = 1e9;
pair <int,LL> go[6][maxn][24];
map <int,int> mp;
LL imp[maxn];
int N,c = 0;
void init(int n,vector <int> s,vector <int> p,vector <int> w,vector <int> l){
N = n;
for (auto &x:s) mp[x] = 0;
for (auto &[x,d]:mp){
imp[++c] = x;
d = c;
}
imp[++c] = 1e18;
REP0(k,c) REP0(i,24){
go[k][n][i] = mkp(n,0);
}
REP0(k,c) REP0(i,n){
if (imp[k] >= s[i]) go[k][i][0] = mkp(w[i], s[i]);
else go[k][i][0] = mkp(l[i], p[i]);
}
REP0(k,c) REP1(j,23) REP0(i,n){
go[k][i][j] = mkp(go[k][go[k][i][j-1].F][j-1].F,
go[k][i][j-1].S + go[k][go[k][i][j-1].F][j-1].S);
}
//REP0(i,n)REP0(j,24) cout << go[c-1][i][j].F << ',' << go[c-1][i][j].S << ' ';cout << '\n';
}
LL simulate(int x,int is){
LL z = is;
REP0(k,c){
if (z >= imp[k+1]) continue;
for (int i=24;i--;) if (z + go[k][x][i].S < imp[k+1] and go[k][x][i].F != N){
z += go[k][x][i].S;
x = go[k][x][i].F;
}
z += go[k][x][0].S;
x = go[k][x][0].F;
if (x == N) return z;
}
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... |