Submission #73089382


Source Code Expand

use proconio::input;

#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize,
        mut A: [i64; N],
    }

    A.sort();

    let sum_A: i64 = A.iter().sum();
    let max_A = A[N - 1];
    // 本数 M → N
    let min_M = (N + 1) / 2;
    let max_M = N;

    let mut candidate_Ls = Vec::new();
    let mut d = 1i64; // divisor
    while d * d <= sum_A {
        if sum_A % d == 0 {
            let L1 = d;
            let M1 = sum_A / L1;
            if M1 >= min_M as i64 && M1 <= max_M as i64 && L1 >= max_A {
                candidate_Ls.push(L1);
            }

            let L2 = sum_A / d;
            if L2 != L1 {
                let M2 = d;
                if M2 >= min_M as i64 && M2 <= max_M as i64 && L2 >= max_A {
                    candidate_Ls.push(L2);
                }
            }
        }
        d += 1;
    }

    let mut valid_Ls = Vec::new();
    for &L in &candidate_Ls {
        if is_valid(&A, L) {
            valid_Ls.push(L);
        }
    }

    valid_Ls.sort();
    valid_Ls.dedup();

    println!("{}", valid_Ls.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(" "));
}

#[allow(non_snake_case)]
fn is_valid(A: &[i64], L: i64) -> bool {
    let N = A.len();
    let mut left = 0;
    let mut right = N - 1;

    while left < right {
        if A[right] == L {
            right -= 1;
        } else if A[right] < L {
            let need = L - A[right];
            if A[left] != need {
                return false;
            }
            left += 1;
            right -= 1;
        } else {
            return false;
        }
    }

    if left == right && A[left] != L {
        return false;
    }

    true
}

Submission Info

Submission Time
Task C - AtCoder Riko
User memoka
Language Rust (rustc 1.89.0)
Score 350
Code Size 1753 Byte
Status AC
Exec Time 58 ms
Memory 9832 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 3
AC × 22
Set Name Test Cases
Sample 0_sample_1.txt, 0_sample_2.txt, 0_sample_3.txt
All 0_sample_1.txt, 0_sample_2.txt, 0_sample_3.txt, 1_1.txt, 1_2.txt, 1_3.txt, 1_4.txt, 1_5.txt, 2_1.txt, 2_2.txt, 2_3.txt, 2_4.txt, 3_1.txt, 3_2.txt, 3_3.txt, 3_4.txt, 3_5.txt, 3_6.txt, 4_1.txt, 4_2.txt, 4_3.txt, 4_4.txt
Case Name Status Exec Time Memory
0_sample_1.txt AC 1 ms 2088 KiB
0_sample_2.txt AC 1 ms 1952 KiB
0_sample_3.txt AC 1 ms 2028 KiB
1_1.txt AC 53 ms 9740 KiB
1_2.txt AC 35 ms 9380 KiB
1_3.txt AC 45 ms 9832 KiB
1_4.txt AC 47 ms 9664 KiB
1_5.txt AC 46 ms 9720 KiB
2_1.txt AC 38 ms 9556 KiB
2_2.txt AC 39 ms 9608 KiB
2_3.txt AC 56 ms 9628 KiB
2_4.txt AC 50 ms 9636 KiB
3_1.txt AC 46 ms 9680 KiB
3_2.txt AC 49 ms 9736 KiB
3_3.txt AC 31 ms 9532 KiB
3_4.txt AC 25 ms 9516 KiB
3_5.txt AC 1 ms 1876 KiB
3_6.txt AC 24 ms 9400 KiB
4_1.txt AC 5 ms 4888 KiB
4_2.txt AC 58 ms 7616 KiB
4_3.txt AC 1 ms 2080 KiB
4_4.txt AC 1 ms 2008 KiB