Submission details
Task:Tulkki
Sender:NicholasAhman
Submission time:2025-11-03 17:13:49 +0200
Language:C++ (C++17)
Status:READY
Result:12
Feedback
groupverdictscore
#1ACCEPTED12
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3details
#2ACCEPTED0.00 s1, 2, 3details
#3ACCEPTED0.00 s1, 2, 3details
#4ACCEPTED0.00 s1, 2, 3details
#5ACCEPTED0.00 s1, 2, 3details
#6ACCEPTED0.00 s1, 2, 3details
#70.00 s2, 3details
#80.00 s2, 3details
#90.00 s2, 3details
#100.00 s2, 3details
#11--2, 3details
#12--2, 3details
#130.00 s3details
#140.00 s3details
#150.00 s3details
#16--3details
#170.00 s3details
#180.00 s3details

Compiler report

input/code.cpp: In function 'void process_token(std::vector<Token>&, std::array<long unsigned int, 26>&, std::vector<Repeat>&, const Token&)':
input/code.cpp:56:18: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::array<long unsigned int, 26>::value_type' {aka 'long unsigned int'} [-Wformat=]
   56 |         printf("%d ", vars[token.data - 'A']);
      |                 ~^
      |                  |
      |                  int
      |                 %ld

Code

#include <array>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <stdint.h>
#include <vector>

enum class TokenType {
    CLEAR,
    INCREASE,
    PRINT,
    REPEAT,
};

struct Token {
    TokenType type;
    uint64_t data;
};

struct Repeat {
    size_t times;
    size_t start;
    size_t end;
};

int trim(char* str, int i) {
    while (true) {
        bool edited = false;
        while (isspace(str[i])) {
            i++;
            edited = true;
        }

        if (str[i] == '#') {
            while (str[i] != '\n') {
                i++;
                edited = true;
            }
        }

        if (!edited) {
            break;
        }
    }

    return i;
}

void process_token(std::vector<Token> &tokens, std::array<uint64_t, 26> &vars, std::vector<Repeat> &repeats, const Token &token) {
    if (token.type == TokenType::CLEAR) {
        vars[token.data - 'A'] = 0;
    } else if (token.type == TokenType::INCREASE) {
        vars[token.data - 'A']++;
    } else if (token.type == TokenType::PRINT) {
        printf("%d ", vars[token.data - 'A']);
    } else if (token.type == TokenType::REPEAT) {
        const Repeat &repeat = repeats[token.data];
        for (size_t i = 0; i < vars[repeat.times - 'A']; i++) {
            for (size_t j = repeat.start; j < repeat.end; j++) {
                process_token(tokens, vars, repeats, tokens[j]);
            }
        }
    }
}

int main() {
    std::vector<Repeat> repeats;
    std::vector<Token> tokens;

    std::array<uint64_t, 26> vars = {0};

    char input[128*1000];
    char *ptr = input;
    size_t len = read(STDIN_FILENO, input, 128*1000);
    input[len] = '\0';
    while (true) {
        int i = 0;
        
        if (ptr[i] == '\0' or ptr[i] == EOF) {
            break;
        }

        i = trim(ptr, 0);

        Token token;
        token.data = 0;

        bool repeat_added = false;

        if (strncmp(ptr + i, "CLEAR", 5) == 0) {
            token.type = TokenType::CLEAR;
            i += 5;
        } else if (strncmp(ptr + i, "INCREASE", 8) == 0) {
            token.type = TokenType::INCREASE;
            i += 8;
        } else if (strncmp(ptr + i, "PRINT", 5) == 0) {
            token.type = TokenType::PRINT;
            i += 5;
        } else if (strncmp(ptr + i, "REPEAT", 6) == 0) {
            token.type = TokenType::REPEAT;
            i += 6;
            repeats.push_back({0, tokens.size()+1, 0});
            repeat_added = true;
        } else if (ptr[i] == '(') {
            ptr += i + 1;
            continue;
        } else if (ptr[i] == ')') {
            repeats.back().end = tokens.size();
            ptr += i + 1;
            continue;
        } else {
            break;
        }

        i = trim(ptr, i);

        token.data = ptr[i];
        
        if (repeat_added) {
            i += 1;
            i = trim(ptr, i);
            if (strncmp(ptr + i, "TIMES", 5) != 0) {
                printf("Error: REPEAT must be followed by TIMES\n");
            }

            i += 5;
            i = trim(ptr, i);

            if (ptr[i] != '(') {
                printf("Error: TIMES must be followed by parentheses\n");
            }

            repeats.back().times = token.data;
            token.data = repeats.size() - 1;
        }

        tokens.push_back(token);
        ptr += i + 1;
    }

    for (auto& token : tokens) {
        process_token(tokens, vars, repeats, token);
    }
}

Test details

Test 1 (public)

Group: 1, 2, 3

Verdict: ACCEPTED

input
PRINT X
INCREASE X
PRINT X
INCREASE X
PRINT X
...

correct output
0 1 2 0 

user output
0 1 2 0 

Test 2 (public)

Group: 1, 2, 3

Verdict: ACCEPTED

input
INCREASE
X
# aybabtu
   PRINT    X
INCREASE # test
...

correct output
1 3 

user output
1 3 

Test 3 (public)

Group: 1, 2, 3

Verdict: ACCEPTED

input
# Create number 3
INCREASE X
INCREASE X
INCREASE X

...

correct output

user output

Test 4 (public)

Group: 1, 2, 3

Verdict: ACCEPTED

input
INCREASE A
PRINT A
INCREASE B
PRINT B
INCREASE C
...

correct output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

user output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

Test 5 (public)

Group: 1, 2, 3

Verdict: ACCEPTED

input
INCREASE X
INCREASE X
INCREASE X
INCREASE X
INCREASE X
...

correct output
999 

user output
999 

Test 6 (public)

Group: 1, 2, 3

Verdict: ACCEPTED

input
PRINT X
PRINT X
PRINT X
PRINT X
PRINT X
...

correct output
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

user output
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

Test 7 (public)

Group: 2, 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
5 5 5 5 5 

user output
5 5 5 5 5 5 

Feedback: Output is longer than expected

Test 8 (public)

Group: 2, 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
0 0 0 0 0 

user output
0 0 

Feedback: Output is shorter than expected

Test 9 (public)

Group: 2, 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
6 7 8 9 10 

user output
(empty)

Test 10 (public)

Group: 2, 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
5 5 

user output
6 6 

Feedback: Incorrect character on line 1 col 1: expected "5", got "6"

Test 11 (public)

Group: 2, 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
20 

user output
(empty)

Test 12 (public)

Group: 2, 3

Verdict:

input
INCREASE A
INCREASE A

INCREASE B
INCREASE B
...

correct output
42 

user output
(empty)

Test 13 (public)

Group: 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 

user output
1 1 

Feedback: Output is shorter than expected

Test 14 (public)

Group: 3

Verdict:

input
# Create number 3
INCREASE A INCREASE A INCREASE...

correct output
12 

user output

Feedback: Incorrect character on line 1 col 1: expected "12", got "5"

Test 15 (public)

Group: 3

Verdict:

input
INCREASE X
INCREASE X
INCREASE X
INCREASE X
INCREASE X
...

correct output
531441 

user output
10 

Feedback: Incorrect character on line 1 col 1: expected "531441", got "10"

Test 16 (public)

Group: 3

Verdict:

input
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
...

correct output
1337 

user output
(empty)

Test 17 (public)

Group: 3

Verdict:

input
INCREASE A
INCREASE A

REPEAT A TIMES (
    REPEAT A TIMES (
...

correct output
1 2 1 2 1 1 3 4 3 4 3 4 3 4 3 ...

user output
2 2 1 2 1 2 1 1 2 

Feedback: Output is shorter than expected

Test 18 (public)

Group: 3

Verdict:

input
# Efficient algorithm for find...

correct output
2 3 5 7 11 13 17 19 23 29 31 3...

user output
3 2 3 4 5 7 15 26 31 32 35 38 ...

Feedback: Output is shorter than expected