CSES - Datatähti 2025 alku - Results
Submission details
Task:Pizzat
Sender:villsukka
Submission time:2024-10-28 14:26:23 +0200
Language:Rust (2021)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.00 sdetails
#12ACCEPTED0.00 sdetails
#13ACCEPTED0.00 sdetails

Code

use std::{io, str::FromStr};

#[derive(Debug)]
struct Pizza {
    people_count: i32,
    slice_count: i32,
}

impl FromStr for Pizza {
    type Err = ();

    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
        let mut parts = s
            .strip_suffix('\n')
            .or(Some(s))
            .expect("Or is always something")
            .split(" ");

        let people_count: i32 = parts
            .next()
            .expect("Missing 1st parameter")
            .parse()
            .expect("1st parameter");
        let pizza_count: i32 = parts
            .next()
            .expect("Missing 2nd parameter")
            .parse()
            .expect("2nd parameter");
        let slices_per_pizza: i32 = parts
            .next()
            .expect("Missing 3rd parameter")
            .parse()
            .expect("3rd parameter");

        Ok(Self {
            people_count,
            slice_count: pizza_count * slices_per_pizza,
        })
    }
}

impl Pizza {
    pub fn count_slices_per_person(&self) -> (i32, i32) {
        let min_slice_per_person = self.slice_count / self.people_count;

        let max_slice_per_person = match self.slice_count % self.people_count {
            0 => min_slice_per_person,
            _ => min_slice_per_person + 1,
        };

        (min_slice_per_person, max_slice_per_person)
    }
}

fn main() {
    let mut input = String::new();

    io::stdin().read_line(&mut input).unwrap();

    let pizza: Pizza = input.parse().unwrap();

    dbg!(&pizza);

    let (x, y) = pizza.count_slices_per_person();

    println!("{} {}", x, y);
}

Test details

Test 1

Verdict: ACCEPTED

input
3 2 4

correct output
2 3

user output
2 3

Error:
[input/code.rs:62] &pizza = Pizza {
    people_count: 3,
    slice_count: 8,
}

Test 2

Verdict: ACCEPTED

input
1 1 1

correct output
1 1

user output
1 1

Error:
[input/code.rs:62] &pizza = Pizza {
    people_count: 1,
    slice_count: 1,
}

Test 3

Verdict: ACCEPTED

input
1 1 2

correct output
2 2

user output
2 2

Error:
[input/code.rs:62] &pizza = Pizza {
    people_count: 1,
    slice_count: 2,
}

Test 4

Verdict: ACCEPTED

input
2 1 1

correct output
0 1

user output
0 1

Error:
[input/code.rs:62] &pizza = Pizza {
    people_count: 2,
    slice_count: 1,
}

Test 5

Verdict: ACCEPTED

input
2 5 7

correct output
17 18

user output
17 18

Error:
[input/code.rs:62] &pizza = Pizza {
    people_count: 2,
    slice_count: 35,
}

Test 6

Verdict: ACCEPTED

input
1 1000 1000

correct output
1000000 1000000

user output
1000000 1000000

Error:
[input/code.rs:62] &pizza = Pizza {
    people_count: 1,
    slice_count: 1000000,
}

Test 7

Verdict: ACCEPTED

input
1000 1000 1000

correct output
1000 1000

user output
1000 1000

Error:
[input/code.rs:62] &pizza = Pizza {
    people_count: 1000,
    slice_count: 1000000,
}

Test 8

Verdict: ACCEPTED

input
1000 1 1

correct output
0 1

user output
0 1

Error:
[input/code.rs:62] &pizza = Pizza {
    people_count: 1000,
    slice_count: 1,
}

Test 9

Verdict: ACCEPTED

input
997 995 997

correct output
995 995

user output
995 995

Error:
[input/code.rs:62] &pizza = Pizza {
    people_count: 997,
    slice_count: 992015,
}

Test 10

Verdict: ACCEPTED

input
997 994 997

correct output
994 994

user output
994 994

Error:
[input/code.rs:62] &pizza = Pizza {
    people_count: 997,
    slice_count: 991018,
}

Test 11

Verdict: ACCEPTED

input
997 996 995

correct output
994 995

user output
994 995

Error:
[input/code.rs:62] &pizza = Pizza {
    people_count: 997,
    slice_count: 991020,
}

Test 12

Verdict: ACCEPTED

input
997 996 996

correct output
995 996

user output
995 996

Error:
[input/code.rs:62] &pizza = Pizza {
    people_count: 997,
    slice_count: 992016,
}

Test 13

Verdict: ACCEPTED

input
997 995 499

correct output
497 498

user output
497 498

Error:
[input/code.rs:62] &pizza = Pizza {
    people_count: 997,
    slice_count: 496505,
}