| Task: | Tulkki |
| Sender: | lukarantalainen |
| Submission time: | 2026-06-07 14:37:08 +0300 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | 100 |
| subtask | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 12 |
| #2 | ACCEPTED | 32 |
| #3 | ACCEPTED | 56 |
| test | verdict | time | subtask | |
|---|---|---|---|---|
| #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.09 s | 3 | details |
| #16 | ACCEPTED | 0.00 s | 3 | details |
| #17 | ACCEPTED | 0.07 s | 3 | details |
| #18 | ACCEPTED | 0.04 s | 3 | details |
Compiler report
input/code.cpp: In function 'std::vector<std::__cxx11::basic_string<char> > parse(const std::string&)':
input/code.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (int i{}; i<len; ++i) {
| ~^~~~
input/code.cpp:55:8: warning: unused variable 'comment' [-Wunused-variable]
55 | bool comment{};
| ^~~~~~~
input/code.cpp: In function 'void read(const std::vector<std::__cxx11::basic_string<char> >&)':
input/code.cpp:84:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for (int i{}; i<commands.size(); ++i) {
| ~^~~~~~~~~~~~~~~~Code
#include <iostream>
#include <map>
#include <string>
#include <sstream>
#include <functional>
#include <limits>
#include <vector>
#include <fstream>
#include <algorithm>
std::map<char, int> vars;
void clear(const std::vector<std::string>& ops);
void increase(const std::vector<std::string>& ops);
void print(const std::vector<std::string>& ops);
void repeat(const std::vector<std::string>& ops);
void read(const std::vector<std::string>& commands);
using Command = std::function<void(const std::vector<std::string>& input)>;
std::unordered_map<std::string, Command> table {
{"CLEAR", clear},
{"INCREASE", increase},
{"PRINT", print},
{"REPEAT", repeat},
};
void call(std::string command, const std::vector<std::string>& input) {
table.at(command)(input);
}
void clear(const std::vector<std::string>& ops) {
char var{ops[0][0]};
vars[var] = 0;
}
void increase(const std::vector<std::string>& ops){
char var{ops[0][0]};
++vars[var];
}
void print(const std::vector<std::string>& ops){
char var{ops[0][0]};
std::cout << vars[var] << " ";
}
void repeat(const std::vector<std::string> &commands){
int limit{vars[commands[0][0]]};
for (int i{}; i<limit; ++i) {
read(std::vector(commands.begin()+3, commands.end()));
}
}
std::vector<std::string> parse(const std::string& i) {
bool comment{};
std::string input{i};
size_t len{input.length()};
for (int i{}; i<len; ++i) {
if (input[i] == '#') {
auto pos{input.find('\n', i)};
if (pos != std::string::npos) {
input.erase(i, pos-i);
len -= pos-i;
} else break;
}
if (input[i] == '\n') input[i] = ' ';
}
std::istringstream ss(input);
std::vector<std::string> commands;
std::string word;
while (ss >> word) {
commands.push_back(word);
}
return commands;
}
void read(const std::vector<std::string>& commands) {
std::string command;
std::vector<std::string> ops;
int open{};
for (int i{}; i<commands.size(); ++i) {
if (commands[i] == "REPEAT") ++open;
if (commands[i] == ")") --open;
if (command == "") {
command = commands[i];
continue;
} else {
ops.push_back(commands[i]);
}
if (command == "REPEAT" && open ) continue;
call(command, ops);
command = "";
ops.clear();
}
}
int main(){
std::ios_base::sync_with_stdio(0);
std::cin.tie(0);
for (int i{}; i<26; ++i) {
vars["ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i]] = 0;
}
std::ifstream input("test_input.txt");
std::string line;
std::string raw_input;
while (std::getline(std::cin, line)) {
raw_input += line+'\n';
}
auto commands{parse(raw_input)};
read(commands);
return 0;
}
Test details
Test 1 (public)
Subtask: 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)
Subtask: 1, 2, 3
Verdict: ACCEPTED
| input |
|---|
| INCREASE X # aybabtu PRINT X INCREASE # test ... |
| correct output |
|---|
| 1 3 |
| user output |
|---|
| 1 3 |
Test 3 (public)
Subtask: 1, 2, 3
Verdict: ACCEPTED
| input |
|---|
| # Create number 3 INCREASE X INCREASE X INCREASE X ... |
| correct output |
|---|
| 3 |
| user output |
|---|
| 3 |
Test 4 (public)
Subtask: 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)
Subtask: 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)
Subtask: 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)
Subtask: 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)
Subtask: 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)
Subtask: 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)
Subtask: 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)
Subtask: 2, 3
Verdict: ACCEPTED
| input |
|---|
| INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A ... |
| correct output |
|---|
| 20 |
| user output |
|---|
| 20 |
Test 12 (public)
Subtask: 2, 3
Verdict: ACCEPTED
| input |
|---|
| INCREASE A INCREASE A INCREASE B INCREASE B ... |
| correct output |
|---|
| 42 |
| user output |
|---|
| 42 |
Test 13 (public)
Subtask: 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)
Subtask: 3
Verdict: ACCEPTED
| input |
|---|
| # Create number 3 INCREASE A INCREASE A INCREASE... |
| correct output |
|---|
| 12 |
| user output |
|---|
| 12 |
Test 15 (public)
Subtask: 3
Verdict: ACCEPTED
| input |
|---|
| INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X ... |
| correct output |
|---|
| 531441 |
| user output |
|---|
| 531441 |
Test 16 (public)
Subtask: 3
Verdict: ACCEPTED
| input |
|---|
| INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A ... |
| correct output |
|---|
| 1337 |
| user output |
|---|
| 1337 |
Test 17 (public)
Subtask: 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)
Subtask: 3
Verdict: ACCEPTED
| input |
|---|
| # Efficient algorithm for find... |
| correct output |
|---|
| 2 3 5 7 11 13 17 19 23 29 31 3... |
| user output |
|---|
| 2 3 5 7 11 13 17 19 23 29 31 3... |
