Submission #496172

#TimeUsernameProblemLanguageResultExecution timeMemory
496172PedroBigManDungeons Game (IOI21_dungeons)C++17
25 / 100
7150 ms2097156 KiB
/* Author of all code: Pedro BIGMAN Dias Last edit: 15/02/2021 */ #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #pragma GCC optimize("Ofast") #include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <string> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <queue> #include <deque> #include <list> #include <iomanip> #include <stdlib.h> #include <time.h> #include <cstring> #include "dungeons.h" using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; #define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++) #define pb push_back #define mp make_pair #define pl pair<ll,ll> #define ff first #define ss second #define whole(x) x.begin(),x.end() #define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl #define INF 500000000000000000LL #define EPS 0.00000001 #define pi 3.14159 #define VV(vvvv,NNNN,xxxx); REP(i,0,NNNN) {vvvv.pb(xxxx);} ll mod=1000000007LL; template<class A=ll> void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;} template<class A=ll> void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}} ll n; vector<ll> s,pp,w,l; set<ll> svalues; class SucPath { public: ll N; vector<ll> fo; vector<vector<ll> > f2; //sparse table of steps powers of 2 vector<vector<ll> > f3; //sparse table of sums ll ms; //max_steps vector<ll> og; ll tresh; SucPath() {N=0LL;} SucPath(vector<ll> x, ll tres, ll max_steps=0LL) { N=x.size(); fo=x; ms=max_steps; tresh=tres; vector<ll> xx; REP(i,0,(ll) (floor(log2(ms)))+1LL) {xx.pb(0LL);} REP(i,0,N) {f2.pb(xx); f3.pb(xx);} Conf2(0); Conf3(0); } void Conf2(ll e) //O(NlogN) { if((1LL<<e)>ms) {return;} if(e==0) {REP(i,0,N) {f2[i][e]=fo[i];} Conf2(e+1);} else { REP(i,0,N) { f2[i][e]=f2[f2[i][e-1]][e-1]; } } Conf2(e+1); } ll f(ll x,ll s) //O(logN) { ll ind=0; while(s>0) { if(s%2!=0) {x=f2[x][ind];} s/=2; ind++; } return x; } void Conf3(ll e) //O(NlogN) { if((1LL<<e)>ms) {return;} if(e==0) {REP(i,0,n) {if(s[i]<=tresh) {f3[i][e]=s[i];} else {f3[i][e]=pp[i];}} f3[n][e]=0; Conf3(e+1);} else { REP(i,0,N) { f3[i][e]=f3[i][e-1]+f3[f2[i][e-1]][e-1]; } } Conf3(e+1); } pl Stop(ll x, ll val) // returns {endpos,added value}, first position so that you added at least val, starting from x { if(val<=0) {return {x,0};} ll e = (ll)log2(ms); ll added=0LL; while(e>=0) { if(f2[x][e]!=N-1 && f3[x][e]<val) {val-=f3[x][e]; added+=f3[x][e]; x=f2[x][e];} e--; } added+=f3[x][0];x=fo[x]; return {x,added}; } }; unordered_map<ll,SucPath> m; void init(int nn, vector<int> ss, vector<int> ppp, vector<int> ww, vector<int> lll) { n=(ll) nn; REP(i,0,n) {s.pb((ll) ss[i]); pp.pb((ll) ppp[i]); w.pb((ll) ww[i]); l.pb((ll) lll[i]);} REP(i,0,n) {svalues.insert(ss[i]);} svalues.insert(0); set<ll>::iterator it = svalues.begin(); while(it!=svalues.end()) { ll curval = *it; it++; ll nextval=INF; if(it!=svalues.end()) {nextval=*it;} vector<ll> f; VV(f,n+1,0); f[n]=n; REP(i,0,n) { if(curval>=s[i]) {f[i]=w[i];} else {f[i]=l[i];} } SucPath XX(f,curval,10000010LL+n); m[curval]=XX; } return; } long long simulate(int x, int zz) { ll z = (ll) zz; set<ll>::iterator it = svalues.upper_bound(z); it--; while(it!=svalues.end()) { it++; ll nextvalue=INF; if(it!=svalues.end()) {nextvalue=*it;} it--; pl next = m[*it].Stop(x,nextvalue-z); z+=next.ss; x=next.ff; it++; } return z; }

Compilation message (stderr)

dungeons.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    5 | #pragma GCC optimization ("O3")
      | 
dungeons.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    6 | #pragma GCC optimization ("unroll-loops")
      | 
dungeons.cpp: In function 'void init(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
dungeons.cpp:135:29: warning: variable 'nextval' set but not used [-Wunused-but-set-variable]
  135 |   ll curval = *it; it++; ll nextval=INF; if(it!=svalues.end()) {nextval=*it;}
      |                             ^~~~~~~
#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...