| Task: | Tulkki |
| Sender: | JuusoH |
| Submission time: | 2025-10-27 19:27:33 +0200 |
| Language: | Rust (2021) |
| Status: | READY |
| Result: | 100 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 12 |
| #2 | ACCEPTED | 32 |
| #3 | ACCEPTED | 56 |
| 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.02 s | 3 | details |
| #16 | ACCEPTED | 0.00 s | 3 | details |
| #17 | ACCEPTED | 0.54 s | 3 | details |
| #18 | ACCEPTED | 0.01 s | 3 | details |
Compiler report
warning: variant `PAR_START` should have an upper camel case name
--> input/code.rs:137:5
|
137 | 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:138:5
|
138 | PAR_END,
| ^^^^^^^ help: convert the identifier to upper camel case: `ParEnd`
warning: field `loop_index` is never read
--> input/code.rs:51:5
|
49 | struct Vars {
| ---- field in this struct
50 | vars: [usize; 30],
51 | loop_index: usize,
| ^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: method `debug_print` is never used
--> input/code.rs:159:8
|
142 | impl Instruction {
| ---------------- method in this implementation
...
159 | fn debug_print(&self) {
| ^^^^^^^^^^^
warning: 4 warnings emittedCode
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();
instructions = vars.create_loops(instructions);
for i in instructions {
//i.debug_print();
vars.execute(i);
}
//println!("{:?}", vars.loops);
}
struct Vars {
vars: [usize; 30],
loop_index: usize,
loops: Vec<Vec<Instruction>>,
}
impl Vars {
fn new() -> Self {
Self {
vars: [0; 30],
loop_index: 0,
loops: vec![],
}
}
fn create_loops(&mut self, instructions: Vec<Instruction>) -> Vec<Instruction> {
let mut loop_index = 0;
let mut largest_loop_index = 0;
let mut indexes: Vec<usize> = vec![];
let mut res = vec![];
for inst in instructions {
match inst {
Instruction::REPEAT(a) => {
let new_loop_index = largest_loop_index + 1;
if loop_index == 0 {
res.push(Instruction::LOOP(a, new_loop_index - 1));
} else {
self.loops[loop_index - 1].push(Instruction::LOOP(a, new_loop_index - 1));
}
self.loops.push(vec![]);
}
Instruction::PAR_START => {
loop_index = largest_loop_index + 1;
largest_loop_index = loop_index;
indexes.push(loop_index);
}
Instruction::PAR_END => {
indexes.pop();
loop_index = *indexes.last().unwrap_or(&0);
}
Instruction::TIMES => {}
_ => {
if loop_index == 0 {
res.push(inst);
} else {
self.loops[loop_index - 1].push(inst);
}
}
}
}
res
}
fn execute(&mut self, inst: Instruction) {
match inst {
Instruction::CLEAR(a) => self.clear(a),
Instruction::INCREASE(a) => self.increase(a),
Instruction::PRINT(a) => self.print(a),
Instruction::LOOP(mut times, loop_index) => {
times = self.vars[times];
//println!("loop: {times} {loop_index}");
for _ in 0..times {
for i in self.loops[loop_index].clone() {
self.execute(i);
}
}
}
_ => {}
}
//println!("index: {current_index}");
//inst.debug_print();
}
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,
///times, loop index
LOOP(usize, usize),
}
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 => (),
Self::LOOP(_, _) => (),
}
}
fn debug_print(&self) {
let res = match self {
Self::CLEAR(a) => format!("CLEAR {a}"),
Self::INCREASE(a) => format!("INCREASE {a}"),
Self::PRINT(a) => format!("PRINT {a}"),
Self::REPEAT(a) => format!("REPEAT {a}"),
Self::TIMES => format!("TIMES"),
Self::PAR_START => "(".to_string(),
Self::PAR_END => ")".to_string(),
Self::LOOP(a, b) => format!("REPEAT {a} TIMES: {b}"),
};
println!("{res}");
}
}
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 ... |
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: 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 ... |
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 ... |
Test 18 (public)
Group: 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 ... |
