Submission details
Task:Tulkki
Sender:lukarantalainen
Submission time:2026-06-07 12:37:44 +0300
Language:C++ (C++20)
Status:READY
Result:44
Feedback
subtaskverdictscore
#1ACCEPTED12
#2ACCEPTED32
#30
Test results
testverdicttimesubtask
#1ACCEPTED0.00 s1, 2, 3details
#2ACCEPTED0.00 s1, 2, 3details
#3ACCEPTED0.00 s1, 2, 3details
#4ACCEPTED0.00 s1, 2, 3details
#5ACCEPTED0.01 s1, 2, 3details
#6ACCEPTED0.01 s1, 2, 3details
#7ACCEPTED0.00 s2, 3details
#8ACCEPTED0.00 s2, 3details
#9ACCEPTED0.00 s2, 3details
#10ACCEPTED0.00 s2, 3details
#11ACCEPTED0.00 s2, 3details
#12ACCEPTED0.00 s2, 3details
#13ACCEPTED0.00 s3details
#140.00 s3details
#150.09 s3details
#160.00 s3details
#170.00 s3details
#180.01 s3details

Compiler report

input/code.cpp: In function 'std::vector<std::__cxx11::basic_string<char> > parse(const std::string&)':
input/code.cpp:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
   58 |   for (int i{}; i<len; ++i) {
      |                 ~^~~~
input/code.cpp:54:8: warning: unused variable 'comment' [-Wunused-variable]
   54 |   bool comment{};
      |        ^~~~~~~
input/code.cpp: In function 'void read(const std::vector<std::__cxx11::basic_string<char> >&)':
input/code.cpp:83: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]
   83 |   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 char var);
void increase(const char var);
void print(const char var);
void repeat(const std::vector<std::string>& ops);
void read(const std::vector<std::string>& commands);

void call(std::string command, const std::vector<std::string>& input) {
  if (command == "CLEAR") {
    clear(static_cast<const char>(input[0][0]));
  }
  else if (command == "INCREASE"){
    increase(static_cast<const char>(input[0][0]));
  }
  else if (command == "PRINT") {
    print(static_cast<const char>(input[0][0]));
  }
  else if (command == "REPEAT") {
    repeat(input);
  }
}

void clear(char var) {  
  vars[var] = 0;
}

void increase(char var){
  (vars.count(var) ? ++vars[var] : vars[var] = 1);
}

void print(char var){
  std::cout << vars[var] << " ";
}

void repeat(const std::vector<std::string> &commands){
  int limit{vars[static_cast<char>(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;
  bool closed{};
  for (int i{}; i<commands.size(); ++i) {
    if (commands[i] == ")") closed = true;
    if (command == "") {
      command = commands[i];
      continue;
    } else {
      ops.push_back(commands[i]);
    }

    if (command == "REPEAT" && !closed) continue;

    call(command, ops);
    closed = false;
    command = "";
    ops.clear();
  }
}

int main(){
  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

user output

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:

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

correct output
12 

user output
(empty)

Feedback: Output is shorter than expected

Test 15 (public)

Subtask: 3

Verdict:

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

correct output
531441 

user output
(empty)

Feedback: Output is shorter than expected

Test 16 (public)

Subtask: 3

Verdict:

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

correct output
1337 

user output
(empty)

Feedback: Output is shorter than expected

Test 17 (public)

Subtask: 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
4 2 4 2 4 2 4 2 4 2 4 2 4 2 4 ...

Feedback: Output is shorter than expected

Test 18 (public)

Subtask: 3

Verdict:

input
# Efficient algorithm for find...

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

user output
6 6 12 18 24 30 36 42 48 54 60...

Feedback: Output is longer than expected