CSES - Datatähti 2025 alku - Results
Submission details
Task:Tikut
Sender:Ez
Submission time:2024-10-28 17:10:25 +0200
Language:Rust (2021)
Status:COMPILE ERROR

Compiler report

error[E0425]: cannot find function `len` in this scope
  --> input/code.rs:16:8
   |
16 |     if len(t) == 0{exit(0)}
   |        ^^^ not found in this scope
   |
help: use the `.` operator to call the method `len` on `&Vec<u32>`
   |
16 -     if len(t) == 0{exit(0)}
16 +     if t.len() == 0{exit(0)}
   |

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.

Code

use std::{cmp::{max, Reverse}, convert::TryInto, io::{BufRead, BufReader}, process::exit};
fn main() {
let mut input = BufReader::new(std::io::stdin());
let mut line = "".to_string();
input.read_line(&mut line).unwrap();
let mut split = line.split_whitespace();
let n: u32 = split.next().unwrap().parse().unwrap();
let m: u32 = split.next().unwrap().parse().unwrap();
input = BufReader::new(std::io::stdin());
line = "".to_string();
input.read_line(&mut line).unwrap();
if n == 0{print!("0"); exit(0)}
split = line.split_whitespace();
let mut t: Vec<u32> = split.map(|x: &str| x.parse::<u32>().unwrap()).collect();
t.sort_by_key(|w: &u32| Reverse(*w));
if len(t) == 0{exit(0)}
let mut s: Vec<u32> = vec![0; n.try_into().unwrap()];
let mut pa: u32 = t[t.len()- 1];
let mut sa: u32 = t[0];
for _i in 0..m as usize{
for ii in 0..n as usize{
if ii as u32 == n - 1 {s[ii] += 1; pa = if pa > lyhyin(t[ii], s[ii]) {lyhyin(t[ii], s[ii])} else {pa}; sa = max(pisin(t[ii], s[ii]), pisin(t[ii+1], s[ii+1])); break}
if pisin(t[ii], s[ii]) > pisin(t[ii+1], s[ii+1]){
s[ii] += 1;
sa = max(pisin(t[ii], s[ii]), pisin(t[ii+1], s[ii+1]));
pa = if pa > lyhyin(t[ii], s[ii]) {lyhyin(t[ii], s[ii])} else {pa};
break
}
}
print!("{} ", sa - pa)
}
}
fn pisin(t: u32, s: u32) -> u32{
return t/(s + 1) + t%(s+1)
}
fn lyhyin(t: u32, s: u32) -> u32{
return t/(s + 1)
}