| Task: | Tulkki |
| Sender: | JuusoH |
| Submission time: | 2025-10-27 17:56:23 +0200 |
| Language: | Rust (2021) |
| Status: | READY |
| Result: | 44 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 12 |
| #2 | ACCEPTED | 32 |
| #3 | RUNTIME ERROR | 0 |
| 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.00 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 | RUNTIME ERROR | 0.61 s | 3 | details |
| #14 | RUNTIME ERROR | 0.40 s | 3 | details |
| #15 | RUNTIME ERROR | 0.40 s | 3 | details |
| #16 | RUNTIME ERROR | 0.61 s | 3 | details |
| #17 | TIME LIMIT EXCEEDED | -- | 3 | details |
| #18 | TIME LIMIT EXCEEDED | -- | 3 | details |
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: unused variable: `l`
--> input/code.rs:84:21
|
84 | for l in 0..self.loops[self.loop_index - 1].0 - 1 {
| ^ help: if this is intentional, prefix it with an underscore: `_l`
warning: value assigne...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 |
|---|
| 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: RUNTIME ERROR
| 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 |
Test 14 (public)
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| # Create number 3 INCREASE A INCREASE A INCREASE... |
| correct output |
|---|
| 12 |
| user output |
|---|
| (empty) |
Test 15 (public)
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X ... |
| correct output |
|---|
| 531441 |
| user output |
|---|
| (empty) |
Test 16 (public)
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A ... |
| correct output |
|---|
| 1337 |
| user output |
|---|
| (empty) |
Test 17 (public)
Group: 3
Verdict: TIME LIMIT EXCEEDED
| 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: TIME LIMIT EXCEEDED
| input |
|---|
| # Efficient algorithm for find... |
| correct output |
|---|
| 2 3 5 7 11 13 17 19 23 29 31 3... |
| user output |
|---|
| (empty) |
