Submission #575867

#TimeUsernameProblemLanguageResultExecution timeMemory
575867PedroBigManCrayfish scrivener (IOI12_scrivener)C++14
0 / 100
800 ms211432 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> using namespace std; typedef 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 1000000000000000000LL #define EPS ((ld)0.00000000001) #define pi ((ld)3.141592653589793) #define VV(vvvv,NNNN,xxxx); REP(iiiii,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);}} class SucPath { public: ll N; vector<ll> fo; vector<vector<ll> > f2; //sparse table of steps powers of 2 ll ms; //max_steps vector<ll> og; SucPath() {N=0LL;} SucPath(vector<ll> x, ll max_steps=0LL) { N=x.size(); fo=x; ms=max_steps; vector<ll> xx; REP(i,0,(ll) (floor(log2(ms)))+1LL) {xx.pb(0LL);} REP(i,0,N) {f2.pb(xx);} Conf2(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; } pl Floyd() //Floyd's Algorithm, O(N) time, O(1) memory, return <element of cycle,length od cycle> { ll a=fo[0]; ll b=fo[fo[0]]; while(a!=b) {a=fo[a]; b=fo[fo[b]];} ll l=1; b=fo[a]; while(b!=a) {b=fo[b]; l++;} return mp(a,l); } }; vector<ll> S; vector<pl> s; vector<vector<pl> > f; //f2[i][exp] = {node after 2^exp moves, number of letters} void Init() { return; } void AddState(ll val, ll nxt) { s.pb({val,nxt}); if(S.size()>nxt) {S.pb(S[nxt]+min(val+1,1));} else {S.pb(1);} ll exp=0; ll curval = min(s[nxt].ff+1,1); if(s.size()==1) {curval=0;} ll ind = s.size()-1; f.pb({}); f[ind].pb({nxt,curval}); ll curind = nxt; while(1>0) { if(curind==0) {break;} f[ind].pb({f[curind][min(exp,(int)f[curind].size()-1)].ff,curval+f[curind][min(exp,(int)f[curind].size()-1)].ss}); curind=f[curind][min(exp,(int)f[curind].size()-1)].ff; curval+=f[curind][min(exp,(int)f[curind].size()-1)].ss; exp++; } } void TypeLetter(char L) { ll val = (ll) (L-'a'); AddState(val,max(0,(int)(s.size()-1))); } void UndoCommands(int U) { AddState(-1,s.size()-1-U); } char GetLetter(int P) { //REP(i,0,s.size()) {REP(j,0,f[i].size()) {cout<<f[i][j].ff<<" "<<f[i][j].ss<<endl;} cout<<endl;} ll needed = S.back()-P; ll curind=s.size()-1; ll curval = min(1,s[curind].ff+1); ll exp = (ll) log2(S.back()); ll poss; ll nxt; ll ans=s[curind].ff; while(curval<needed) { poss=curval+f[curind][min(exp,(int)f[curind].size()-1)].ss; if(poss<needed) {curval+=poss; curind = f[curind][min(exp,(int)f[curind].size()-1)].ff; exp--; continue;} if(poss>needed) {exp--; continue;} nxt = f[curind][min(exp,(int)f[curind].size()-1)].ff; if(s[nxt].ff>=0) {ans = s[nxt].ff; break;} exp--; } return ((char) ans+'a'); }

Compilation message (stderr)

scrivener.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    5 | #pragma GCC optimization ("O3")
      | 
scrivener.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    6 | #pragma GCC optimization ("unroll-loops")
      | 
scrivener.cpp: In function 'void AddState(ll, ll)':
scrivener.cpp:114:13: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'int'} [-Wsign-compare]
  114 |  if(S.size()>nxt) {S.pb(S[nxt]+min(val+1,1));} else {S.pb(1);}
      |     ~~~~~~~~^~~~
#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...