Submission details
Task:Tulkki
Sender:Mariia
Submission time:2025-11-01 10:53:38 +0200
Language:C++ (C++20)
Status:READY
Result:44
Feedback
groupverdictscore
#1ACCEPTED12
#2ACCEPTED32
#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
#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
#14ACCEPTED0.00 s3details
#15ACCEPTED0.03 s3details
#16ACCEPTED0.00 s3details
#17ACCEPTED0.06 s3details
#18--3details

Compiler report

input/code.cpp: In function 'int repeatt(int, long long int, int)':
input/code.cpp:21:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<command>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         for (int j = i + 1; j < commands.size(); j++) {
      |                             ~~^~~~~~~~~~~~~~~~~
input/code.cpp:31:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<command>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |                     while (j < commands.size() && commands[j].level > curLevel) {
      |                            ~~^~~~~~~~~~~~~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:53:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for (int i = 0; i < s.size();) {
      |                         ~...

Code

#include <iostream>
#include <vector>
#include <cctype>
#include <string>
#include <algorithm>

using namespace std;

struct command {
    int level;
    string type;
    int var;
};

vector<long long> var(30, 0);
vector<command> commands;

int repeatt(int curLevel, long long times, int i) {
    int endInd = commands.size();
    for (int t = 0; t < times; t++) {
        for (int j = i + 1; j < commands.size(); j++) {
            if (commands[j].level < curLevel) {
                endInd = j;
                break;
            }
            //cout << j << ' ' << commands[j].level << ' ' << commands[j].type << ' ' << commands[j].var << '\n';
            if (commands[j].type == "repeat") {
                if (var[commands[j].var] != 0) {
                    j = repeatt(curLevel + 1,  var[commands[j].var], j) - 1;
                } else {
                    while (j < commands.size() && commands[j].level > curLevel) {
                        j++;
                    }
                }
            } else if (commands[j].type == "clear") {
                var[commands[j].var] = 0;
            } else if (commands[j].type == "increase") {
                var[commands[j].var] += 1;
            } else if (commands[j].type == "print") {
                cout << var[commands[j].var] << ' ';
            }
        }
    }
    return endInd;
}

int main() {
    string prevCommand;
    int level = 1;
    string s;
    while (getline(cin, s)) {
        //if (s.empty()) break;
        for (int i = 0; i < s.size();) {
            if (s[i] == '#') break;
            if (i + 5 <= s.size() && s.substr(i, 5) == "CLEAR") {
                prevCommand = "clear";
                i += 5;
            } else if (i + 8 <= s.size() && s.substr(i, 8) == "INCREASE") {
                prevCommand = "increase";
                i += 8;
            } else if (i + 5 <= s.size() && s.substr(i, 5) == "PRINT") {
                prevCommand = "print";
                i += 5;
            } else if (i + 6 <= s.size() && s.substr(i, 6) == "REPEAT") {
                prevCommand = "repeat";
                i += 6;
            } else if ('A' <= s[i] && s[i] <= 'Z') {
                int v = s[i] - 'A';
                commands.push_back({level, prevCommand, v});
                i += 1;
                if (prevCommand == "repeat") {
                    i += 6;
                    level++;
                }
            } else if (s[i] == ')') {
                level--;
                i++;
            } else {
                i += 1;
            }
        }
    }
    /*for (int i = 0; i < commands.size(); i++) {
        cout << i << ' ' << commands[i].level << ' ' << commands[i].type << ' ' << commands[i].var << '\n';
    } */
    for (int i = 0; i < commands.size(); i++) {
        //cout << i << ' ' << commands[i].level << ' ' << commands[i].type << ' ' << commands[i].var << '\n';
        if (commands[i].type == "repeat") {
            if (var[commands[i].var] != 0) {
                i = repeatt(2, var[commands[i].var], i) - 1;
            } else {
                while (commands[i].level > 1) {
                    i++;
                }
            }
        } else if (commands[i].type == "clear") {
            var[commands[i].var] = 0;
        } else if (commands[i].type == "increase") {
            var[commands[i].var] += 1;
        } else if (commands[i].type == "print") {
            cout << var[commands[i].var] << ' ';
        }
    }
}

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: 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:

input
# Efficient algorithm for find...

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

user output
(empty)