이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define pb push_back
#define all(v) v.begin(),v.end()
const ll M=4e5+10;
const ll inf=2e18;
vector<pair<pii,int>>inc[M];
ll awin[M];
ll N;
vector<int>lose;
void init(int n,vector<int>s,vector<int>p,vector<int>w,vector<int>l) {
N=n;
w.pb(n),l.pb(n);
s.pb(0);
for(auto it:l)
lose.pb(it);
for(int i=n-1;i>=0;i--){
for(auto &it:inc[w[i]])
inc[i].pb(it);
for(auto &it:inc[i])
it.F.F-=s[i],it.F.S+=s[i];
while(inc[i].size()&&inc[i].back().F.F<s[i])
inc[i].pop_back();
inc[i].pb({{s[i],0},i});
}
awin[n]=0;
for(int i=n-1;i>=0;i--){
awin[i]=awin[w[i]]+s[i];
}
}
long long simulate(int x, int z){
ll res=0;
while(1){
if(x==N)
break;
if(inc[x].back().F.F<=z+res){
return res+awin[x]+z;
}
ll l=0,r=inc[x].size()-1,mid,ind;
while(l<=r){
mid=((l+r)>>1);
if(inc[x][mid].F.F>z+res)
r=mid-1,ind=mid;
else
l=mid+1;
}
res+=inc[x][ind].F.S;
x=inc[x][ind].S;
res+=inc[x][0].F.F;
x=lose[x];
}
return res+z;
}
컴파일 시 표준 에러 (stderr) 메시지
dungeons.cpp: In function 'long long int simulate(int, int)':
dungeons.cpp:54:18: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
54 | res+=inc[x][ind].F.S;
| ^
# | 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... |