Submission details
Task:Tulkki
Sender:JuusoH
Submission time:2025-10-27 17:55:47 +0200
Language:Rust (2021)
Status:READY
Result:12
Feedback
groupverdictscore
#1ACCEPTED12
#20
#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
#70.00 s2, 3details
#80.00 s2, 3details
#90.00 s2, 3details
#100.00 s2, 3details
#110.00 s2, 3details
#120.00 s2, 3details
#13--3details
#14--3details
#15--3details
#16--3details
#17--3details
#18--3details

Compiler report

warning: variant `PAR_START` should have an upper camel case name
   --> input/code.rs:119:5
    |
119 |     PAR_START,
    |     ^^^^^^^^^ help: convert the identifier to upper camel case: `ParStart`
    |
    = note: `#[warn(non_camel_case_types)]` on by default

warning: variant `PAR_END` should have an upper camel case name
   --> input/code.rs:120:5
    |
120 |     PAR_END,
    |     ^^^^^^^ help: convert the identifier to upper camel case: `ParEnd`

warning: variable `debug_indent` is assigned to, but never used
  --> input/code.rs:67:17
   |
67 |         let mut debug_indent = self.loop_index;
   |                 ^^^^^^^^^^^^
   |
   = note: consider using `_debug_indent` instead
   = note: `#[warn(unused_variables)]` on by default

warning: value assigned to `debug_indent` is never read
  --> input/code.rs:92:17
   |
92 |                 debug_indent -= 1;
   |                 ^^^^^^^^^^^^
   |
   = help: maybe it is overwritten before being read?
   = note: `#[warn(unused_ass...

Code

use std::io::{self, Read};
fn main() {
    //input and setup
    let mut stdin = io::stdin();
    let mut input = String::new();
    _ = stdin.read_to_string(&mut input);
    let instruction_lines = input.split("\n");
    let mut instructions: Vec<Instruction> = vec![];
    for line in instruction_lines {
        for keyword in line.to_string().split_whitespace() {
            if keyword.contains("#") {
                let before_comment = keyword.split("#").next().unwrap();
                if before_comment.len() > 0 {
                    match before_comment {
                        "CLEAR" => instructions.push(Instruction::CLEAR(100)),
                        "INCREASE" => instructions.push(Instruction::INCREASE(100)),
                        "PRINT" => instructions.push(Instruction::PRINT(100)),
                        "REPEAT" => instructions.push(Instruction::REPEAT(100)),
                        "TIMES" => instructions.push(Instruction::TIMES),
                        "(" => instructions.push(Instruction::PAR_START),
                        ")" => instructions.push(Instruction::PAR_END),
                        _ => instructions.last_mut().unwrap().set_add(keyword),
                    };
                }
                break;
            }
            match keyword {
                "CLEAR" => instructions.push(Instruction::CLEAR(100)),
                "INCREASE" => instructions.push(Instruction::INCREASE(100)),
                "PRINT" => instructions.push(Instruction::PRINT(100)),
                "REPEAT" => instructions.push(Instruction::REPEAT(100)),
                "TIMES" => instructions.push(Instruction::TIMES),
                "(" => instructions.push(Instruction::PAR_START),
                ")" => instructions.push(Instruction::PAR_END),
                _ => instructions.last_mut().unwrap().set_add(keyword),
            };
        }
    }

    let mut vars = Vars::new();

    for i in instructions {
        vars.execute(i, 0);
    }
}

struct Vars {
    vars: [usize; 30],
    loop_index: usize,
    loops: Vec<(usize, Vec<Instruction>)>,
}
impl Vars {
    fn new() -> Self {
        Self {
            vars: [0; 30],
            loop_index: 0,
            loops: vec![],
        }
    }
    fn execute(&mut self, inst: Instruction, current_index: usize) {
        if let Instruction::PAR_END = inst {
        } else {
            if self.loop_index > current_index {
                self.loops[self.loop_index - 1].1.push(inst);
            }
        }
        let mut debug_indent = self.loop_index;
        match inst {
            Instruction::CLEAR(a) => self.clear(a),
            Instruction::INCREASE(a) => self.increase(a),
            Instruction::PRINT(a) => self.print(a),
            Instruction::REPEAT(a) => {
                self.loops.push((self.vars[a] as usize, vec![]));
            }
            Instruction::TIMES => (),
            Instruction::PAR_START => {
                self.loop_index += 1;
            }
            Instruction::PAR_END => {
                println!("looping {} times.", self.loops[self.loop_index - 1].0);
                for i in self.loops[self.loop_index - 1].1.clone() {
                    println!("loop: {:?}", i);
                }
                for l in 0..self.loops[self.loop_index - 1].0 - 1 {
                    for i in self.loops[self.loop_index - 1].1.clone() {
                        self.execute(i, self.loop_index);
                        println!("loop inst executed: {:?}", i);
                    }
                    println!("loop done: {l}");
                }

                debug_indent -= 1;
                self.loop_index -= 1;
                self.loops.remove(self.loop_index);
                if self.loop_index > 0 {
                    self.loops[self.loop_index - 1].1.push(inst);
                }
            }
        }
        //inst.debug_print(debug_indent);
    }
    fn clear(&mut self, add: usize) {
        self.vars[add] = 0;
    }
    fn increase(&mut self, add: usize) {
        self.vars[add] += 1;
    }
    fn print(&self, add: usize) {
        println!("{}", self.vars[add]);
    }
}
#[derive(Clone, Copy, Debug)]
enum Instruction {
    CLEAR(usize),
    INCREASE(usize),
    PRINT(usize),
    REPEAT(usize),
    TIMES,
    PAR_START,
    PAR_END,
}
impl Instruction {
    fn set_add(&mut self, add_str: &str) {
        let char = add_str.chars().next().unwrap();
        let a = 'A' as usize;
        let curr = char as usize;
        let add = curr - a;
        match self {
            Self::CLEAR(a) => *a = add,
            Self::INCREASE(a) => *a = add,
            Self::PRINT(a) => *a = add,
            Self::REPEAT(a) => *a = add,
            Self::TIMES => (),
            Self::PAR_START => (),
            Self::PAR_END => (),
        }
    }
    fn debug_print(&self, loop_index: usize) {
        let indent = "  ".repeat(loop_index);
        let mut rest = String::new();
        match self {
            Self::CLEAR(a) => rest = format!("CLEAR {a}"),
            Self::INCREASE(a) => rest = format!("INCREASE {a}"),
            Self::PRINT(a) => rest = format!("PRINT {a}"),
            Self::REPEAT(a) => rest = format!("REPEAT {a}"),
            Self::TIMES => rest = format!("TIMES"),
            Self::PAR_START => rest = "(".to_string(),
            Self::PAR_END => rest = ")".to_string(),
        }
        println!("{indent}{rest}");
    }
}

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

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

Test 7 (public)

Group: 2, 3

Verdict:

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

correct output
5 5 5 5 5 

user output
5
looping 5 times.
loop: PRINT(0)
5
loop inst executed: PRINT(0)
...

Feedback: Output is longer than expected

Test 8 (public)

Group: 2, 3

Verdict:

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

correct output
0 0 0 0 0 

user output
0
looping 5 times.
loop: CLEAR(0)
loop: PRINT(0)
loop inst executed: CLEAR(0)
...

Feedback: Output is longer than expected

Test 9 (public)

Group: 2, 3

Verdict:

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

correct output
6 7 8 9 10 

user output
6
looping 5 times.
loop: INCREASE(0)
loop: PRINT(0)
loop inst executed: INCREASE(0...

Feedback: Output is longer than expected

Test 10 (public)

Group: 2, 3

Verdict:

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

correct output
5 5 

user output
looping 5 times.
loop: INCREASE(1)
loop: INCREASE(2)
loop inst executed: INCREASE(1...

Feedback: Output is longer than expected

Test 11 (public)

Group: 2, 3

Verdict:

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

correct output
20 

user output
looping 5 times.
loop: INCREASE(0)
loop inst executed: INCREASE(0...

Feedback: Output is longer than expected

Test 12 (public)

Group: 2, 3

Verdict:

input
INCREASE A
INCREASE A

INCREASE B
INCREASE B
...

correct output
42 

user output
looping 3 times.
loop: INCREASE(0)
loop: INCREASE(1)
loop inst executed: INCREASE(0...

Feedback: Output is longer than expected

Test 13 (public)

Group: 3

Verdict:

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
(empty)

Test 14 (public)

Group: 3

Verdict:

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

correct output
12 

user output
(empty)

Test 15 (public)

Group: 3

Verdict:

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

correct output
531441 

user output
(empty)

Test 16 (public)

Group: 3

Verdict:

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

correct output
1337 

user output
(empty)

Test 17 (public)

Group: 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
(empty)

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)