Submission #914602

# Submission time Handle Problem Language Result Execution time Memory
914602 2024-01-22T11:30:08 Z Wansur Dungeons Game (IOI21_dungeons) C++17
0 / 100
7000 ms 315676 KB
#include<bits/stdc++.h>
#define ent '\n'

typedef long long ll;
using namespace std;
const int mx=1e6+12;

vector<int> A,B,C,D;
int up[23][mx];
ll ma[23][mx];
ll sum[23][mx];
int N,m,k;
bool ok=0;

void init(int M, vector<int> s, vector<int> p, vector<int> w, vector<int> l){
	N=M;
	A=s,B=p;
	C=w,D=l;
	s.push_back(0);
	s.push_back(0);
	for(int k=0;k<22;k++){
		up[k][N]=up[k][N+1]=N+1;
	}
	for(int i=N-1;i>=0;i--){
		up[0][i]=w[i];
		ma[0][i]=s[i];
		sum[0][i]=s[i];
		for(int k=1;k<22;k++){
			up[k][i]=up[k-1][up[k-1][i]];
			ma[k][i]=max(ma[k-1][i],ma[k-1][up[k-1][i]]);
			sum[k][i]=sum[k-1][i]+sum[k-1][up[k-1][i]];
		}
	}
}

long long simulate(int pos, int d){
	if(ok)return 0;
	int n=N;
	ll x=d;
	vector<int> s=A,p=B,w=C,l=D;
	int cnt=0;
	ll prev=x;
	while(pos<n){
//		while(pos<n && s[pos]<=x){
//			x+=s[pos];
//			pos=w[pos];
//		}
//		if(pos==n)break;
//		x+=p[pos];
//		pos=l[pos];
//		if(prev*2-100>x){
//			assert(0);
//		}
//		continue;
		for(int k=21;k>=0;k--){ 
			if(up[k][pos]<=n && ma[k][pos]<=x){
				x+=sum[k][pos];
				pos=up[k][pos];
			}
		}
		if(pos==n)break;
		if(s[pos]<=x){
			x+=s[pos];
			pos=w[pos];
		}
		else{
			x+=p[pos];
			pos=l[pos];
		}
		if(prev*2-100>x){
			ok=1;
			return 0;
		}
		prev=x;
	}
	return x;
}

Compilation message

dungeons.cpp: In function 'long long int simulate(int, int)':
dungeons.cpp:41:6: warning: unused variable 'cnt' [-Wunused-variable]
   41 |  int cnt=0;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 133720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 133724 KB Output is correct
2 Execution timed out 7068 ms 315676 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 133744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 133744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 133744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 133724 KB Output is correct
2 Execution timed out 7068 ms 315676 KB Time limit exceeded
3 Halted 0 ms 0 KB -