Submission #2555045


Source Code Expand

use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn naive(seq: &mut Vec<i64>, cnt: usize) -> usize {
    let n = seq.len();
    for i in 0..cnt {
        seq.sort();
        seq.reverse();
        if seq[0] < n as i64 {
            return i;
        }
        seq[0] -= n as i64;
        for j in 1..n {
            seq[j] += 1;
        }
    }
    cnt
}

fn main() {
    let n = read::<usize>();
    let mut seq = vec![0i64; n];
    for i in 0..n {
        seq[i] = read::<i64>();
    }
    let mut ans = 0;
    ans += naive(&mut seq, 100);
    if seq[n - 1] >= n as i64 {
        for i in 0..n {
            let cnt = std::cmp::max(seq[i] / (n as i64 + 1) - 1, 0);
            ans += (n + 1) * cnt as usize;
            seq[i] -= cnt * (n as i64 + 1);
            assert!(seq[i] >= n as i64);
        }
    }
    ans += naive(&mut seq, 10000);
    // println!("{:?}", seq);
    println!("{}", ans);
}

Submission Info

Submission Time
Task E - Decrease (Judge ver.)
User cos
Language Rust (1.15.1)
Score 600
Code Size 1320 Byte
Status AC
Exec Time 5 ms
Memory 4352 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 5
AC × 35
Set Name Test Cases
Sample example0, example1, example2, example3, example4
All example0, example1, example2, example3, example4, maxrand0, maxrand1, maxrand2, maxrand3, maxrand4, maxrand5, maxrand6, maxrand7, maxrand8, maxrand9, rand0, rand1, rand2, rand3, rand4, rand5, rand6, rand7, rand8, rand9, small0, small1, small2, small3, small4, small5, small6, small7, small8, small9
Case Name Status Exec Time Memory
example0 AC 2 ms 4352 KB
example1 AC 2 ms 4352 KB
example2 AC 2 ms 4352 KB
example3 AC 2 ms 4352 KB
example4 AC 2 ms 4352 KB
maxrand0 AC 2 ms 4352 KB
maxrand1 AC 5 ms 4352 KB
maxrand2 AC 2 ms 4352 KB
maxrand3 AC 5 ms 4352 KB
maxrand4 AC 2 ms 4352 KB
maxrand5 AC 4 ms 4352 KB
maxrand6 AC 2 ms 4352 KB
maxrand7 AC 4 ms 4352 KB
maxrand8 AC 2 ms 4352 KB
maxrand9 AC 4 ms 4352 KB
rand0 AC 2 ms 4352 KB
rand1 AC 2 ms 4352 KB
rand2 AC 2 ms 4352 KB
rand3 AC 2 ms 4352 KB
rand4 AC 2 ms 4352 KB
rand5 AC 2 ms 4352 KB
rand6 AC 2 ms 4352 KB
rand7 AC 3 ms 4352 KB
rand8 AC 2 ms 4352 KB
rand9 AC 2 ms 4352 KB
small0 AC 2 ms 4352 KB
small1 AC 2 ms 4352 KB
small2 AC 2 ms 4352 KB
small3 AC 2 ms 4352 KB
small4 AC 2 ms 4352 KB
small5 AC 3 ms 4352 KB
small6 AC 2 ms 4352 KB
small7 AC 2 ms 4352 KB
small8 AC 2 ms 4352 KB
small9 AC 3 ms 4352 KB