답안 #1049906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1049906 2024-08-09T06:01:49 Z Alihan_8 던전 (IOI21_dungeons) C++17
63 / 100
5137 ms 2097152 KB
#include "dungeons.h"
#include <vector>

#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
//#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

const i64 inf = 1e15;

const int L = 30;

vector <int> s, p, w, l;

int n;

struct Jump{
	vector <vector<i64>> U, S, need;
	
	int n, lim;
	
	Jump() {}
	
	void modify(vector <int> p, vector <int> w, int lim_){
		n = p.size(); lim = lim_;
		
		S.resize(n + 1); 
		U.resize(n + 1);
		need.resize(n + 1);
		
		for ( int i = 0; i <= n; i++ ){
			S[i].resize(L);
			U[i].resize(L);
			need[i].resize(L);
			
			if ( i == n ) continue;
			
			S[i][0] = w[i];
			U[i][0] = p[i];
			need[i][0] = (s[i] >= lim ? s[i] : inf);
		}
	
		U[n][0] = n;
		S[n][0] = inf;
		
		for ( int i = 1; i < L; i++ ){
			for ( int j = 0; j <= n; j++ ){
				U[j][i] = U[U[j][i - 1]][i - 1];
				S[j][i] = min(inf, S[j][i - 1] + S[U[j][i - 1]][i - 1]);
				need[j][i] = min(need[j][i - 1], need[U[j][i - 1]][i - 1] - S[j][i - 1]);
			}
		}
	}
	
	i64 simulate(int &u, i64 z, i64 rq){
		for ( int i = L - 1; i >= 0; i-- ){
			if ( U[u][i] == n ) continue;
			
			if ( rq == inf || (need[u][i] > z && z + S[u][i] < rq) ){
				z += S[u][i];
				u = U[u][i];
			}
		}
		
		if ( u != n && z < rq ){
			if ( s[u] <= z ){
				z += s[u];
				u = w[u];
			} else{
				z += p[u];
				u = l[u];
			}
		}
		
		return z;
	};
};

vector <Jump> A;

vector <i64> v;

void init(int n_, std::vector<int> s_, std::vector<int> p_, std::vector<int> w_, std::vector<int> l_) {
	n = n_, s = s_, p = p_, w = w_, l = l_;
	
	//~ for ( auto &u: s ) v.pb(u);
	
	v.pb(inf);
	
	for ( int i = 0; i <= L; i++ ){
		v.pb(1LL << i);
	}
	
	sort(all(v));
	
	v.resize(unique(all(v)) - v.begin());
	
	for ( auto &x: v ){
		vector <int> fa(n), wh(n);
		
		for ( int i = 0; i < n; i++ ){
			if ( s[i] < x ){
				fa[i] = w[i];
				wh[i] = s[i];
			} else{
				fa[i] = l[i];
				wh[i] = p[i];
			}
		}
		
		Jump h; h.modify(fa, wh, x);
		
		A.pb(h);
	}
}

long long simulate(int x, int Z) {
	// subtask #4
	
	i64 z = Z;
	
	for ( int i = 0; i + 2 < (int)v.size(); i++ ){
		z = A[i].simulate(x, z, v[i + 1]);
	}
	
	z = A.back().simulate(x, z, inf);
	
	return z;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 43 ms 54592 KB Output is correct
4 Correct 1616 ms 1359372 KB Output is correct
5 Correct 42 ms 54648 KB Output is correct
6 Correct 1539 ms 1359276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 27480 KB Output is correct
2 Runtime error 2696 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 27480 KB Output is correct
2 Correct 2035 ms 1360004 KB Output is correct
3 Correct 2198 ms 1360396 KB Output is correct
4 Correct 2382 ms 1361180 KB Output is correct
5 Correct 1987 ms 1361120 KB Output is correct
6 Correct 2076 ms 1361316 KB Output is correct
7 Correct 2210 ms 1361256 KB Output is correct
8 Correct 2496 ms 1361140 KB Output is correct
9 Correct 1740 ms 1361040 KB Output is correct
10 Correct 2280 ms 1360820 KB Output is correct
11 Correct 2678 ms 1361312 KB Output is correct
12 Correct 5137 ms 1361280 KB Output is correct
13 Correct 4549 ms 1361408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 27480 KB Output is correct
2 Correct 2035 ms 1360004 KB Output is correct
3 Correct 2198 ms 1360396 KB Output is correct
4 Correct 2382 ms 1361180 KB Output is correct
5 Correct 1987 ms 1361120 KB Output is correct
6 Correct 2076 ms 1361316 KB Output is correct
7 Correct 2210 ms 1361256 KB Output is correct
8 Correct 2496 ms 1361140 KB Output is correct
9 Correct 1740 ms 1361040 KB Output is correct
10 Correct 2280 ms 1360820 KB Output is correct
11 Correct 2678 ms 1361312 KB Output is correct
12 Correct 5137 ms 1361280 KB Output is correct
13 Correct 4549 ms 1361408 KB Output is correct
14 Correct 25 ms 27484 KB Output is correct
15 Correct 1944 ms 1361540 KB Output is correct
16 Correct 2009 ms 1361780 KB Output is correct
17 Correct 2259 ms 1361164 KB Output is correct
18 Correct 2232 ms 1361276 KB Output is correct
19 Correct 2056 ms 1361276 KB Output is correct
20 Correct 2144 ms 1361016 KB Output is correct
21 Correct 2301 ms 1361348 KB Output is correct
22 Correct 2172 ms 1361092 KB Output is correct
23 Correct 2972 ms 1361244 KB Output is correct
24 Correct 3472 ms 1361540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 27480 KB Output is correct
2 Correct 2035 ms 1360004 KB Output is correct
3 Correct 2198 ms 1360396 KB Output is correct
4 Correct 2382 ms 1361180 KB Output is correct
5 Correct 1987 ms 1361120 KB Output is correct
6 Correct 2076 ms 1361316 KB Output is correct
7 Correct 2210 ms 1361256 KB Output is correct
8 Correct 2496 ms 1361140 KB Output is correct
9 Correct 1740 ms 1361040 KB Output is correct
10 Correct 2280 ms 1360820 KB Output is correct
11 Correct 2678 ms 1361312 KB Output is correct
12 Correct 5137 ms 1361280 KB Output is correct
13 Correct 4549 ms 1361408 KB Output is correct
14 Correct 25 ms 27484 KB Output is correct
15 Correct 1944 ms 1361540 KB Output is correct
16 Correct 2009 ms 1361780 KB Output is correct
17 Correct 2259 ms 1361164 KB Output is correct
18 Correct 2232 ms 1361276 KB Output is correct
19 Correct 2056 ms 1361276 KB Output is correct
20 Correct 2144 ms 1361016 KB Output is correct
21 Correct 2301 ms 1361348 KB Output is correct
22 Correct 2172 ms 1361092 KB Output is correct
23 Correct 2972 ms 1361244 KB Output is correct
24 Correct 3472 ms 1361540 KB Output is correct
25 Correct 1620 ms 1360772 KB Output is correct
26 Correct 2068 ms 1361788 KB Output is correct
27 Correct 1873 ms 1361064 KB Output is correct
28 Correct 1911 ms 1361308 KB Output is correct
29 Correct 2032 ms 1361536 KB Output is correct
30 Correct 2457 ms 1361288 KB Output is correct
31 Correct 2766 ms 1361060 KB Output is correct
32 Correct 2744 ms 1361280 KB Output is correct
33 Correct 2159 ms 1360640 KB Output is correct
34 Correct 2829 ms 1360608 KB Output is correct
35 Correct 2183 ms 1361136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 27480 KB Output is correct
2 Runtime error 2696 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -