Submission #237457

#TimeUsernameProblemLanguageResultExecution timeMemory
237457nicolaalexandraCrayfish scrivener (IOI12_scrivener)C++14
100 / 100
645 ms97400 KiB
#include <bits/stdc++.h> #define DIM 1000010 using namespace std; int v[DIM],tip[DIM],fth[DIM],level[DIM],dp[DIM][20]; int nr_nodes,k; void Init(){} void TypeLetter (char L) { int nod = v[k]; int vecin = ++nr_nodes; v[++k] = nr_nodes; //L[nod].push_back(vecin); //L[vecin].push_back(nod); tip[vecin] = L - 'a'; /// fth[i] - primul nod (in sus) care e litera if (tip[nod] == -1) /// e nod de undo fth[vecin] = fth[nod]; else fth[vecin] = nod; level[vecin] = 1 + level[fth[vecin]]; /// stramosi 2^k dp[vecin][0] = fth[vecin]; for (int i=1;i<=20;i++) dp[vecin][i] = dp[dp[vecin][i-1]][i-1]; } void UndoCommands(int U) { int nod = v[k-U]; int vecin = ++nr_nodes; v[++k] = nr_nodes; tip[vecin] = -1; if (tip[nod] == -1) fth[vecin] = fth[nod]; else fth[vecin] = nod; } char GetLetter(int P) { int nod = v[k]; if (tip[nod] == -1) nod = fth[nod]; int val = level[nod] - P - 1; for (int i=20;i>=0;i--){ if ((1<<i) <= val){ val -= (1<<i); nod = dp[nod][i]; } } return (char)(tip[nod] + 'a'); }

Compilation message (stderr)

scrivener.cpp: In function 'void TypeLetter(char)':
scrivener.cpp:33:22: warning: iteration 19 invokes undefined behavior [-Waggressive-loop-optimizations]
         dp[vecin][i] = dp[dp[vecin][i-1]][i-1];
         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
scrivener.cpp:32:19: note: within this loop
     for (int i=1;i<=20;i++)
                  ~^~~~
#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...