Task: | Key cutting |
Sender: | Kekoäly |
Submission time: | 2024-11-16 16:34:15 +0200 |
Language: | Rust (2021) |
Status: | READY |
Result: | RUNTIME ERROR |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.00 s | details |
#7 | ACCEPTED | 0.00 s | details |
#8 | ACCEPTED | 0.00 s | details |
#9 | RUNTIME ERROR | 0.42 s | details |
#10 | RUNTIME ERROR | 0.42 s | details |
#11 | RUNTIME ERROR | 0.42 s | details |
#12 | RUNTIME ERROR | 0.42 s | details |
#13 | RUNTIME ERROR | 0.43 s | details |
#14 | ACCEPTED | 0.32 s | details |
Code
#!allow(unused) use std::io::stdin; fn take_int() -> usize { let mut input = String::new(); stdin().read_line(&mut input).unwrap(); return input.trim().parse().unwrap(); } fn take_vector() -> Vec<usize> { let mut input = String::new(); stdin().read_line(&mut input).unwrap(); let arr: Vec<usize> = input.trim().split_whitespace().map(|x| x.parse().unwrap()).collect(); arr } fn solve(lista: Vec<usize>) -> usize { // println!("{:?}", lista); if lista.len() == 0 { return 0 } /* if lista.len() == 1 { return 1 } */ if !lista.contains(&0) { let minu = *lista.iter().min().unwrap(); // println!("{}", minu); let mut new: Vec<usize> = Vec::new(); for elem in lista.iter() { new.push(*elem - minu); } return 1 + solve(new); } else { let a:usize = lista.iter().position(|&x| x==0).unwrap(); let b = a+1; /* let l = lista.len(); while b < l { if lista[b] == 0 { break } else { b += 1; } } */ return solve(lista[..a].to_vec()) + solve(lista[b..].to_vec()); } } fn main() { let _ = take_int(); let lista = take_vector(); println!("{}", solve(lista)) }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
3 1 2 1 |
correct output |
---|
2 |
user output |
---|
2 |
Test 2
Verdict: ACCEPTED
input |
---|
1 0 |
correct output |
---|
0 |
user output |
---|
0 |
Test 3
Verdict: ACCEPTED
input |
---|
1 9 |
correct output |
---|
1 |
user output |
---|
1 |
Test 4
Verdict: ACCEPTED
input |
---|
100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... |
correct output |
---|
0 |
user output |
---|
0 |
Test 5
Verdict: ACCEPTED
input |
---|
100 0 0 0 1 1 0 0 0 0 1 1 1 0 1 1 ... |
correct output |
---|
25 |
user output |
---|
25 |
Test 6
Verdict: ACCEPTED
input |
---|
100 2 1 2 1 2 0 0 0 1 1 2 2 1 2 2 ... |
correct output |
---|
41 |
user output |
---|
41 |
Test 7
Verdict: ACCEPTED
input |
---|
100 36 5 10 37 94 59 20 31 64 2 58... |
correct output |
---|
99 |
user output |
---|
99 |
Test 8
Verdict: ACCEPTED
input |
---|
100 228768416 32415139 952687252 6... |
correct output |
---|
100 |
user output |
---|
100 |
Test 9
Verdict: RUNTIME ERROR
input |
---|
100000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... |
correct output |
---|
0 |
user output |
---|
(empty) |
Test 10
Verdict: RUNTIME ERROR
input |
---|
100000 1 1 1 0 0 1 0 0 0 0 1 0 1 0 0 ... |
correct output |
---|
24965 |
user output |
---|
(empty) |
Test 11
Verdict: RUNTIME ERROR
input |
---|
100000 2 1 2 2 2 2 2 1 1 0 1 1 0 1 1 ... |
correct output |
---|
38968 |
user output |
---|
(empty) |
Test 12
Verdict: RUNTIME ERROR
input |
---|
100000 4 4 5 4 4 5 0 2 2 1 4 4 1 0 5 ... |
correct output |
---|
59156 |
user output |
---|
(empty) |
Test 13
Verdict: RUNTIME ERROR
input |
---|
100000 18 5 6 16 8 10 1 7 4 15 5 9 19... |
correct output |
---|
82598 |
user output |
---|
(empty) |
Test 14
Verdict: ACCEPTED
input |
---|
100000 33 37 37 86 42 38 18 10 77 57 ... |
correct output |
---|
94897 |
user output |
---|
94897 |