Submission #425733

#TimeUsernameProblemLanguageResultExecution timeMemory
425733dxz05크레이피쉬 글쓰는 기계 (IOI12_scrivener)C++14
12 / 100
1088 ms2580 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 3e2;

int commands;
int prv[N];
bool ok[N];
char ch[N];

void dbg(){
    return;
    for (int i = 0; i < commands; i++) cout << ch[i] << ' '; cout << endl;
    for (int i = 0; i < commands; i++) cout << ok[i] << ' '; cout << endl;
    cout << endl;
}

void Init() {
    commands = 0;
    fill(ch, ch + N, '?');
}

void TypeLetter(char L) {
    ok[commands] = true;
    prv[commands] = 1e9;
    ch[commands] = L;
    commands++;
    dbg();
}

vector<int> undo;

void UndoCommands(int U) {
    ok[commands] = true;
    prv[commands] = commands - U;
    undo.push_back(commands);

    for (int x : undo){
        if (x >= commands - U) prv[commands] = min(prv[commands], prv[x]);
    }

    for (int i = prv[commands]; i < commands; i++) ok[i] ^= 1;

    commands++;
    dbg();
}

char GetLetter(int P) {
    char ans;
    for (int i = 0; i < commands; i++){
        if (ok[i] && ch[i] != '?'){
            if (P == 0){
                ans = ch[i];
                break;
            }
            P--;
        }
    }

    dbg();

    return ans;
}

/**
14
T a
T b
P 1
T d
U 2
U 1
P 2
T e
U 1
U 5
T c
P 2
U 2
P 2
*/

Compilation message (stderr)

scrivener.cpp: In function 'void dbg()':
scrivener.cpp:14:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   14 |     for (int i = 0; i < commands; i++) cout << ch[i] << ' '; cout << endl;
      |     ^~~
scrivener.cpp:14:62: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   14 |     for (int i = 0; i < commands; i++) cout << ch[i] << ' '; cout << endl;
      |                                                              ^~~~
scrivener.cpp:15:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   15 |     for (int i = 0; i < commands; i++) cout << ok[i] << ' '; cout << endl;
      |     ^~~
scrivener.cpp:15:62: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   15 |     for (int i = 0; i < commands; i++) cout << ok[i] << ' '; cout << endl;
      |                                                              ^~~~
scrivener.cpp: In function 'char GetLetter(int)':
scrivener.cpp:63:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |     return ans;
      |            ^~~
#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...