| Task: | Tulkki |
| Sender: | rottis |
| Submission time: | 2025-10-27 01:45:33 +0200 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 44 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 12 |
| #2 | ACCEPTED | 32 |
| #3 | TIME LIMIT EXCEEDED | 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.01 s | 1, 2, 3 | details |
| #7 | ACCEPTED | 0.00 s | 2, 3 | details |
| #8 | ACCEPTED | 0.00 s | 2, 3 | details |
| #9 | ACCEPTED | 0.00 s | 2, 3 | details |
| #10 | ACCEPTED | 0.00 s | 2, 3 | details |
| #11 | ACCEPTED | 0.00 s | 2, 3 | details |
| #12 | ACCEPTED | 0.00 s | 2, 3 | details |
| #13 | ACCEPTED | 0.00 s | 3 | details |
| #14 | ACCEPTED | 0.00 s | 3 | details |
| #15 | ACCEPTED | 0.01 s | 3 | details |
| #16 | ACCEPTED | 0.00 s | 3 | details |
| #17 | ACCEPTED | 0.57 s | 3 | details |
| #18 | TIME LIMIT EXCEEDED | -- | 3 | details |
Compiler report
input/code.cpp: In function 'void execute()':
input/code.cpp:122:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
122 | while (instruction_pointer < nodes.size()) {
| ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
input/code.cpp:135:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
135 | if (instruction_pointer + 1 >= nodes.size()) {
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
input/code.cpp:143:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
143 | if (instruction_pointer + 1 >= nodes.size()) {
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
input/code.cpp:151:45: warning:...Code
#include <iostream>
#include <string>
#include <vector>
enum InstructionType {
CLEAR,
INCREMENT,
PRINT,
REPEAT,
TIMES,
VARIABLE,
BRACKET_LEFT,
BRACKET_RIGHT,
NOOP
};
typedef struct Node {
char type;
char value;
} Instruction;
Node convert_string(std::string str) {
if (str == "PRINT") {
return Node {InstructionType::PRINT, 0};
} else if (str == "INCREASE") {
return Node {InstructionType::INCREMENT, 0};
} else if (str == "CLEAR") {
return Node {InstructionType::CLEAR, 0};
} else if (str == "REPEAT") {
return Node {InstructionType::REPEAT, 0};
} else if (str == "TIMES") {
return Node {InstructionType::TIMES, 0};
} else if (str == "(") {
return Node {InstructionType::BRACKET_LEFT, 0};
} else if (str == ")") {
return Node {InstructionType::BRACKET_RIGHT, 0};
} else if (str[0] >= 'A' && str[0] <= 'Z') {
return Node {InstructionType::VARIABLE, str[0]};
} else {
return Node {InstructionType::NOOP, 0};
}
}
bool is_whitespace(char c) {
return (c == ' ' || c == '\n' || c == '\t');
}
int variables[26];
/* CLEAR X (tyhjennys): asettaa muuttujan X arvoksi nollan */
void clear(Node node) {
variables[node.value - 'A'] = 0;
}
/* INCREASE X (lisäys): kasvattaa muuttujan X arvoa yhdellä */
void increment(Node node) {
variables[node.value - 'A']++;
}
/* PRINT X (tulostus): tulostaa muuttujan X arvon */
void print(Node node) {
std::cout << variables[node.value - 'A'] << ' ';
std::cout.flush();
}
/* REPEAT X TIMES ( ... ) (silmukka): suorittaa suluissa olevan koodin muuttujan X arvon verran kertoja */
void execute() {
for (int i = 0; i < 26; i++) {
variables[i] = 0;
}
bool second_last_line = true;
bool last_line = true;
std::string c_line;
std::string buf;
std::vector<Node> nodes;
// set to true if there is a loop with 0 iterations, just skips all nodes until finds the right bracket
bool skip_loop = false;
int instruction_pointer = 0;
int current_loop_depth = 0;
int loop_begin_addresses[1000];
int loop_iters_left[1000];
while (second_last_line) {
second_last_line = last_line;
last_line = (std::getline(std::cin, c_line) ? 1 : 0);
c_line.push_back('\n'); // trailing whitespace to process entire line
for (unsigned int i = 0; i < c_line.size(); i++) {
char c = c_line[i];
if (is_whitespace(c) || c == '#') {
Node node = convert_string(buf);
if (node.type != InstructionType::NOOP) {
//std::cout << "Parsed input: \"" << buf << "\"" << std::endl;
nodes.push_back(node);
}
buf = "";
} else {
buf += c;
}
if (c == '#') {
buf = "";
break;
}
}
while (instruction_pointer < nodes.size()) {
Node instruction = nodes[instruction_pointer];
if (skip_loop) {
if (instruction.type == InstructionType::BRACKET_RIGHT) {
skip_loop = false;
current_loop_depth -= 1;
}
instruction_pointer++;
continue;
}
if (instruction.type == InstructionType::PRINT) {
if (instruction_pointer + 1 >= nodes.size()) {
break;
}
//std::cout << "Printing " << nodes[instruction_pointer + 1].value << std::endl;
print(nodes[instruction_pointer + 1]);
instruction_pointer += 2;
} else if (instruction.type == InstructionType::INCREMENT) {
if (instruction_pointer + 1 >= nodes.size()) {
break;
}
//std::cout << "Incrementing " << nodes[instruction_pointer + 1].value << std::endl;
increment(nodes[instruction_pointer + 1]);
instruction_pointer += 2;
} else if (instruction.type == InstructionType::CLEAR) {
if (instruction_pointer + 1 >= nodes.size()) {
break;
}
//std::cout << "Clearing " << nodes[instruction_pointer + 1].value << std::endl;
clear(nodes[instruction_pointer + 1]);
instruction_pointer += 2;
} else if (instruction.type == InstructionType::REPEAT) {
if (instruction_pointer + 1 >= nodes.size()) {
break;
}
current_loop_depth += 1;
loop_iters_left[current_loop_depth] = variables[nodes[instruction_pointer + 1].value - 'A'];
if (loop_iters_left[current_loop_depth] == 0) {
skip_loop = true;
}
// one loop means we skip back to beginning zero times
loop_iters_left[current_loop_depth]--;
instruction_pointer += 2;
} else if (instruction.type == InstructionType::TIMES) {
//std::cout << "Beginning loop: depth: " << current_loop_depth << ", iters left: " <<
//loop_iters_left[current_loop_depth] << std::endl;
loop_begin_addresses[current_loop_depth] = instruction_pointer + 2;
instruction_pointer += 2;
} else if (instruction.type == InstructionType::BRACKET_LEFT) {
/* should never be here but oh well */
instruction_pointer++;
} else if (instruction.type == InstructionType::BRACKET_RIGHT) {
if (loop_iters_left[current_loop_depth] > 0) {
//std::cout << "Looping again, depth= " << current_loop_depth << std::endl;
instruction_pointer = loop_begin_addresses[current_loop_depth];
loop_iters_left[current_loop_depth]--;
} else { // done with loop
//std::cout << "Done with loop " << current_loop_depth << std::endl;
current_loop_depth--;
instruction_pointer++;
}
}
}
}
}
/*
PRINT X
INCREASE X
PRINT X
INCREASE X
PRINT X
CLEAR X
PRINT X
*/
/*
INCREASE A
INCREASE A
INCREASE A
INCREASE A
INCREASE A
REPEAT A TIMES (
INCREASE A
PRINT A
)
*/
/*
# Create number 3
INCREASE A INCREASE A INCREASE A
# Create number 4
INCREASE B INCREASE B INCREASE B INCREASE B
# Calculate 3 * 4
REPEAT A TIMES ( REPEAT B TIMES ( INCREASE C ) )
# Print result
PRINT C
*/
/*
INCREASE
X
# aybabtu
PRINT X
INCREASE # test
X INCREASE X PRINT#X
X
*/
int main(void) {
execute();
return 0;
}
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: ACCEPTED
| 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 |
Test 8 (public)
Group: 2, 3
Verdict: ACCEPTED
| input |
|---|
| INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A ... |
| correct output |
|---|
| 0 0 0 0 0 |
| user output |
|---|
| 0 0 0 0 0 |
Test 9 (public)
Group: 2, 3
Verdict: ACCEPTED
| input |
|---|
| INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A ... |
| correct output |
|---|
| 6 7 8 9 10 |
| user output |
|---|
| 6 7 8 9 10 |
Test 10 (public)
Group: 2, 3
Verdict: ACCEPTED
| input |
|---|
| INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A ... |
| correct output |
|---|
| 5 5 |
| user output |
|---|
| 5 5 |
Test 11 (public)
Group: 2, 3
Verdict: ACCEPTED
| input |
|---|
| INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A ... |
| correct output |
|---|
| 20 |
| user output |
|---|
| 20 |
Test 12 (public)
Group: 2, 3
Verdict: ACCEPTED
| input |
|---|
| INCREASE A INCREASE A INCREASE B INCREASE B ... |
| correct output |
|---|
| 42 |
| user output |
|---|
| 42 |
Test 13 (public)
Group: 3
Verdict: ACCEPTED
| 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 2 2 3 3 3 4 4 4 4 5 5 5 5 5 |
Test 14 (public)
Group: 3
Verdict: ACCEPTED
| input |
|---|
| # Create number 3 INCREASE A INCREASE A INCREASE... |
| correct output |
|---|
| 12 |
| user output |
|---|
| 12 |
Test 15 (public)
Group: 3
Verdict: ACCEPTED
| input |
|---|
| INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X ... |
| correct output |
|---|
| 531441 |
| user output |
|---|
| 531441 |
Test 16 (public)
Group: 3
Verdict: ACCEPTED
| input |
|---|
| INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A ... |
| correct output |
|---|
| 1337 |
| user output |
|---|
| 1337 |
Test 17 (public)
Group: 3
Verdict: ACCEPTED
| 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 |
|---|
| 1 2 1 2 1 1 3 4 3 4 3 4 3 4 3 ... |
Test 18 (public)
Group: 3
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| # Efficient algorithm for find... |
| correct output |
|---|
| 2 3 5 7 11 13 17 19 23 29 31 3... |
| user output |
|---|
| (empty) |
