Submission #237456

# Submission time Handle Problem Language Result Execution time Memory
237456 2020-06-06T16:50:06 Z nicolaalexandra Crayfish scrivener (IOI12_scrivener) C++14
5 / 100
411 ms 71288 KB
#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[nod];

    /// 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

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 time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 364 ms 71288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 411 ms 66628 KB Output isn't correct
2 Halted 0 ms 0 KB -