| Task: | Tulkki |
| Sender: | NicholasAhman |
| Submission time: | 2025-11-03 17:12:41 +0200 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 12 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 12 |
| #2 | WRONG ANSWER | 0 |
| #3 | WRONG ANSWER | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | 1, 2, 3 | details |
| #2 | ACCEPTED | 0.00 s | 1, 2, 3 | details |
| #3 | ACCEPTED | 0.00 s | 1, 2, 3 | details |
| #4 | ACCEPTED | 0.00 s | 1, 2, 3 | details |
| #5 | ACCEPTED | 0.00 s | 1, 2, 3 | details |
| #6 | ACCEPTED | 0.00 s | 1, 2, 3 | details |
| #7 | WRONG ANSWER | 0.00 s | 2, 3 | details |
| #8 | WRONG ANSWER | 0.00 s | 2, 3 | details |
| #9 | WRONG ANSWER | 0.00 s | 2, 3 | details |
| #10 | WRONG ANSWER | 0.00 s | 2, 3 | details |
| #11 | WRONG ANSWER | 0.00 s | 2, 3 | details |
| #12 | WRONG ANSWER | 0.00 s | 2, 3 | details |
| #13 | WRONG ANSWER | 0.00 s | 3 | details |
| #14 | WRONG ANSWER | 0.00 s | 3 | details |
| #15 | WRONG ANSWER | 0.00 s | 3 | details |
| #16 | WRONG ANSWER | 0.00 s | 3 | details |
| #17 | WRONG ANSWER | 0.00 s | 3 | details |
| #18 | WRONG ANSWER | 0.00 s | 3 | details |
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
| %ldCode
#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 < repeat.times; 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;
printf("Ptr: %s\n", ptr + i);
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 |
|---|
| 3 |
| user output |
|---|
| 3 |
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: WRONG ANSWER
| input |
|---|
| INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A ... |
| correct output |
|---|
| 5 5 5 5 5 |
| user output |
|---|
| Ptr: TIMES ( PRINT A ) 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ... |
Feedback: Output is longer than expected
Test 8 (public)
Group: 2, 3
Verdict: WRONG ANSWER
| input |
|---|
| INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A ... |
| correct output |
|---|
| 0 0 0 0 0 |
| user output |
|---|
| Ptr: TIMES ( CLEAR A PRINT A ) ... |
Feedback: Output is longer than expected
Test 9 (public)
Group: 2, 3
Verdict: WRONG ANSWER
| input |
|---|
| INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A ... |
| correct output |
|---|
| 6 7 8 9 10 |
| user output |
|---|
| Ptr: TIMES ( INCREASE A PRINT A ) ... |
Feedback: Output is longer than expected
Test 10 (public)
Group: 2, 3
Verdict: WRONG ANSWER
| input |
|---|
| INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A ... |
| correct output |
|---|
| 5 5 |
| user output |
|---|
| Ptr: TIMES ( INCREASE B INCREASE C ) ... |
Feedback: Output is longer than expected
Test 11 (public)
Group: 2, 3
Verdict: WRONG ANSWER
| input |
|---|
| INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A ... |
| correct output |
|---|
| 20 |
| user output |
|---|
| Ptr: TIMES ( INCREASE A ) REPEAT A TIMES ( ... |
Feedback: Output is longer than expected
Test 12 (public)
Group: 2, 3
Verdict: WRONG ANSWER
| input |
|---|
| INCREASE A INCREASE A INCREASE B INCREASE B ... |
| correct output |
|---|
| 42 |
| user output |
|---|
| Ptr: TIMES ( INCREASE A INCREASE B ) ... |
Feedback: Output is longer than expected
Test 13 (public)
Group: 3
Verdict: WRONG ANSWER
| 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 |
|---|
| Ptr: TIMES ( INCREASE B REPEAT B TIMES ( PRINT B ) ... |
Feedback: Output is longer than expected
Test 14 (public)
Group: 3
Verdict: WRONG ANSWER
| input |
|---|
| # Create number 3 INCREASE A INCREASE A INCREASE... |
| correct output |
|---|
| 12 |
| user output |
|---|
| Ptr: TIMES ( REPEAT B TIMES (... |
Feedback: Output is longer than expected
Test 15 (public)
Group: 3
Verdict: WRONG ANSWER
| input |
|---|
| INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X ... |
| correct output |
|---|
| 531441 |
| user output |
|---|
| Ptr: TIMES ( REPEAT X TIMES ( REPEAT X TIMES ( REPEAT X TIMES ( REPEAT X TIMES... |
Feedback: Output is longer than expected
Test 16 (public)
Group: 3
Verdict: WRONG ANSWER
| input |
|---|
| INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A ... |
| correct output |
|---|
| 1337 |
| user output |
|---|
| Ptr: TIMES ( REPEAT B TIMES ( INCREASE B ) INCREASE B ... |
Feedback: Output is longer than expected
Test 17 (public)
Group: 3
Verdict: WRONG ANSWER
| 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 |
|---|
| Ptr: TIMES ( REPEAT A TIMES ( INCREASE B CLEAR C REPEAT B TIMES ( ... |
Feedback: Output is shorter than expected
Test 18 (public)
Group: 3
Verdict: WRONG ANSWER
| input |
|---|
| # Efficient algorithm for find... |
| correct output |
|---|
| 2 3 5 7 11 13 17 19 23 29 31 3... |
| user output |
|---|
| Ptr: TIMES ( INCREASE X CLEAR A REPEAT B TIMES ( INCREASE A ... |
Feedback: Output is longer than expected
