#include "dungeons.h"
#include <vector>
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
typedef long long ll;
ll s[400005],p[400005],w[400005],l[400005],cost[400005],to[24][400005];
ll n;
int dp[24][400005][12];
ll suma[24][400005][12];
int who[24][400005][12];
ll smax=0;
void init(int N, std::vector<int> S, std::vector<int> P, std::vector<int> W, std::vector<int> L)
{
n=N;
for(int i=0;i<n;i++)
{
s[i]=S[i];
smax=max(smax,s[i]*1LL);
p[i]=P[i];
w[i]=W[i];
l[i]=L[i];
}
w[n]=n;
for(int k=0;k<24;k++)
{
for(int i=0;i<n;i++)
{
if(s[i]<(1<<k))
{
to[k][i]=w[i];
cost[i]=s[i];
}
else
{
to[k][i]=l[i];
cost[i]=p[i];
}
suma[k][i][0]=cost[i];
who[k][i][0]=to[k][i];
}
cost[n]=0;
to[k][n]=n;
who[k][n][0]=n;
suma[k][n][0]=0;
for(int j=1;j<12;j++)
{
for(int i=0;i<=n;i++)
{
ll sum=0;
ll x=i;
for(int c=1;c<=4;c++)
{
sum+=suma[k][x][j-1];
x=who[k][x][j-1];
}
who[k][i][j]=x;
suma[k][i][j]=sum;
}
}
for(int i=0;i<n;i++)
{
if(s[i]>=(1<<k))
dp[k][i][0]=0-s[i];
else
dp[k][i][0]=-1e9;
}
for(int j=1;j<12;j++)
{
for(int i=0;i<=n;i++)
{
ll x=i;
ll maxim=-1e9;
ll sum=0;
for(int c=1;c<=4;c++)
{
maxim=max(maxim,min(0LL,dp[k][x][j-1]+sum));
sum+=suma[k][x][j-1];
x=who[k][x][j-1];
}
dp[k][i][j]=maxim;
}
}
}
}
long long simulate(int x, int z)
{
ll rez=z;
int cnt=0;
while(x!=n)
{
ll k=0;
for(int i=0;i<24;i++)
if((1<<i)<rez)
k=i;
for(int i=11;i>=0;i--)
{
while(rez+dp[k][x][i]<0)
{
rez+=suma[k][x][i];
x=who[k][x][i];
}
}
rez+=s[x];
x=w[x];
}
return rez;
}
Compilation message
dungeons.cpp: In function 'long long int simulate(int, int)':
dungeons.cpp:90:9: warning: unused variable 'cnt' [-Wunused-variable]
90 | int cnt=0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
205404 KB |
Output is correct |
2 |
Correct |
20 ms |
205404 KB |
Output is correct |
3 |
Correct |
28 ms |
213852 KB |
Output is correct |
4 |
Correct |
287 ms |
450556 KB |
Output is correct |
5 |
Correct |
29 ms |
213868 KB |
Output is correct |
6 |
Correct |
303 ms |
450256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
209756 KB |
Output is correct |
2 |
Correct |
4273 ms |
1911024 KB |
Output is correct |
3 |
Correct |
3556 ms |
1911180 KB |
Output is correct |
4 |
Correct |
4041 ms |
1911980 KB |
Output is correct |
5 |
Correct |
5168 ms |
1912216 KB |
Output is correct |
6 |
Correct |
3974 ms |
1911256 KB |
Output is correct |
7 |
Correct |
3336 ms |
1908856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
209744 KB |
Output is correct |
2 |
Correct |
379 ms |
450304 KB |
Output is correct |
3 |
Execution timed out |
7032 ms |
450128 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
209744 KB |
Output is correct |
2 |
Correct |
379 ms |
450304 KB |
Output is correct |
3 |
Execution timed out |
7032 ms |
450128 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
209744 KB |
Output is correct |
2 |
Correct |
379 ms |
450304 KB |
Output is correct |
3 |
Execution timed out |
7032 ms |
450128 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
209756 KB |
Output is correct |
2 |
Correct |
4273 ms |
1911024 KB |
Output is correct |
3 |
Correct |
3556 ms |
1911180 KB |
Output is correct |
4 |
Correct |
4041 ms |
1911980 KB |
Output is correct |
5 |
Correct |
5168 ms |
1912216 KB |
Output is correct |
6 |
Correct |
3974 ms |
1911256 KB |
Output is correct |
7 |
Correct |
3336 ms |
1908856 KB |
Output is correct |
8 |
Correct |
25 ms |
209744 KB |
Output is correct |
9 |
Correct |
379 ms |
450304 KB |
Output is correct |
10 |
Execution timed out |
7032 ms |
450128 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |