제출 #615619

#제출 시각아이디문제언어결과실행 시간메모리
615619Clan328던전 (IOI21_dungeons)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int n;
vector<pair<int, int>> G, W;
vi dp;

int getDP(int i) {
	if (dp[i] != -1) return dp[i];
	if (i == n) {
		dp[i] = 0;
		return 0;
	}
	dp[i] = W[i].first+getDP(G[i].first);
	return dp[i];
}

void init(int nx, vi s, vi p, vi w, vi l) {
	n = nx;
	G = vector<pii>(n);
	W = vector<pii>(n);
	for (int i = 0; i < n; i++) {
		G[i] = {w[i], l[i]};
		W[i] = {s[i], p[i]};
	}

	dp = vi(n+1, -1);
	for (int i = 0; i <= n; i++) {
		dp[i] = getDP(i);
	}
}

ll simulate(int x, int z) {
	ll currStrength = z, currCnt = 0;
	vi cnt(n);
	vi strength(n);

	int idx = -1;
	for (int i = x; i != n; ) {
		currCnt++;
		if (cnt[i] != 0) {
			idx = i;
			break;
		}
		cnt[i] = currCnt;
		strength[i] = currStrength;

		if (currStrength >= W[i].first) {
			currStrength += W[i].first;
			i = G[i].first;
		} else {
			currStrength += W[i].second;
			i = G[i].second;
		}
	}

	if (idx == -1) return currStrength;

	int cycleStrength = currStrength-strength[idx];
	int remStrength = W[0].first-currStrength;
	currStrength += (remStrength/cycleStrength)*cycleStrength;

	idx = -1;
	for (int i = idx; i != n; ) {
		if (currStrength >= W[0].first) {
			idx = i;
			break;
		}
		if (currStrength >= W[i].first) {
			currStrength += W[i].first;
			i = G[i].first;
		} else {
			currStrength += W[i].second;
			i = G[i].second;
		}
	}

	if (idx == -1) return currStrength;

	return currStrength + dp[idx];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...