Submission #575937

#TimeUsernameProblemLanguageResultExecution timeMemory
575937PedroBigManCrayfish scrivener (IOI12_scrivener)C++14
34 / 100
1087 ms259260 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);}} 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; ll inc; while(1>0) { if(curind==0) {break;} nxt = f[curind][min(exp,(int)f[curind].size()-1)].ff; ll inc = f[curind][min(exp,(int)f[curind].size()-1)].ss; f[ind].pb({nxt,curval+inc}); curind=nxt; curval+=inc; 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) { ll needed = S.back()-P; ll curind=s.size()-1; ll curval = min(1,s[curind].ff+1); ll exp = (ll) log2(s.size()+1); ll poss; ll nxt; //REP(i,0,s.size()) {REP(j,0,f[i].size()) {cout<<f[i][j].ff<<" "<<f[i][j].ss<<endl;} cout<<endl;} ll ans=-1; if(curval==needed) {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--; } if(ans>=0) {return ((char) ans+'a');} return ans; }

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:60:13: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'int'} [-Wsign-compare]
   60 |  if(S.size()>nxt) {S.pb(S[nxt]+min(val+1,1));} else {S.pb(1);}
      |     ~~~~~~~~^~~~
scrivener.cpp:62:57: warning: unused variable 'inc' [-Wunused-variable]
   62 |  f.pb({}); f[ind].pb({nxt,curval}); ll curind = nxt; ll inc;
      |                                                         ^~~
#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...