제출 #1009860

#제출 시각아이디문제언어결과실행 시간메모리
1009860mindiyakDungeons Game (IOI21_dungeons)C++17
0 / 100
7080 ms12704 KiB
#include "dungeons.h" #include <bits/stdc++.h> #include <string> #include <iostream> #include <cmath> #include <numeric> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; typedef pair<int, int> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<vector<int>> vvi; typedef vector<vector<ll>> vvl; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; #define FOR(i, a, b) for (int i = a; i < (b); i++) #define F0R(i, a) for (int i = 0; i < (a); i++) #define FORd(i, a, b) for (int i = (b)-1; i >= a; i--) #define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--) #define trav(a, x) for (auto &a : x) #define uid(a, b) uniform_int_distribution<int>(a, b)(rng) #define len(x) (int)(x).size() #define mp make_pair #define pb push_back #define F first #define nl endl #define S second #define lb lower_bound #define ub upper_bound #define aint(x) x.begin(), x.end() #define raint(x) x.rbegin(), x.rend() #define ins insert const int MOD = 1000000007; vi S,P,W,L,x; vl dist,loopedsum,loopedend,looped; int N; vvl loop_ends,loop_sums; void dfs(int start,int pos,ll sum,set<int> vis){ if(vis.count(pos)){ looped[start] = loop_ends[start].size()-1; loopedend[start] = pos; if(pos == start){ loopedsum[start] = sum; } return; } vis.insert(pos); loop_ends[start].pb(pos); loop_sums[start].pb(sum); if(sum >= S[0])return; sum += P[pos]; pos = L[pos]; dfs(start,pos,sum,vis); } void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) { S = s; P = p; W = w; L = l; N = n; dist = vl(n+1,-1); looped = vl(n+1,-1); loopedsum = vl(n+1,0); loopedend = vl(n+1,0); loop_ends = vvl(n+1,vl()); loop_sums = vvl(n+1,vl()); dist[n] = 0; for(int i = n-1;i>=0;i--){ dist[i] = dist[W[i]] + 1; } FOR(i,0,n){ set<int> vis; dfs(i,i,0,vis); } // cout << "############" << endl; // FOR(i,0,n){ // cout << i << " -> " << endl; // for(auto a:loop_ends[i])cout << a << " "; // cout << endl; // for(auto a:loop_sums[i])cout << a << " "; // cout << endl; // cout << endl; // } // for(auto a:looped)cout << a << " "; // cout << endl; // for(auto a:loopedsum)cout << a << " "; // cout << endl; // for(auto a:loopedend)cout << a << " "; // cout << endl; // cout << "############" << endl; } long long simulate(int x, int z) { // cout << "1 " << x << " " << z << endl; if(x == N)return z; if(z < S[x]){ ll ans = z; ll need = S[x] - z; int n = loop_ends[x].size(); if(looped[x] != -1){ if(loopedsum[x] != 0){ if(need >= loopedsum[x]){ ll counter = need/loopedsum[x]; ans += loopedsum[x] * counter; need = S[x] - ans; } } else{ if(need >= loop_sums[x][looped[x]]){ return simulate(loop_ends[x][looped[x]],ans+loop_sums[x][looped[x]]); } } } // cout << "2 " << ans << " " << need << endl; if(ans >= S[x]){ return ans+S[x]*(dist[x]); } int pos = lower_bound(loop_sums[x].begin(),loop_sums[x].end(),need) - loop_sums[x].begin(); // cout << "3 " << pos << endl; if(pos == n)return simulate(loop_ends[x][pos-1],ans+loop_sums[x][pos-1]); return simulate(loop_ends[x][pos],ans+loop_sums[x][pos]); } return z+S[x]*(dist[x]); }
#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...