Submission #6460524


Source Code Expand

Copy
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

/*

1 2 3 4 5 6 7 8 9
5
1 0 1 1 0
=> 0 1 1 1 0

1 2 3 4 5 6 7 8 9
8
1 1 0 1 0 0 0 1
0 0 0 0 0 0 0 1

*/

fn main() {
    let N = read!(usize);
    let mut A = read![[i64]];

    A.insert(0, 0);
    let mut dp = vec![0; N + 1];

    for i in (1..N + 1).rev() {
        let mut m = 2;
        let mut s = A[i];
        while i * m <= N {
            s ^= dp[i * m];
            m += 1;
        }
        dp[i] = s;
    }
    debug!(dp);

    let M = (1..N + 1)
        .filter_map(|i| {
            if dp[i] != 0 {
                Some(i.to_string())
            } else {
                None
            }
        })
        .collect::<Vec<_>>();

    println!("{}", M.len());
    println!("{}", M.join(" "));
}

Submission Info

Submission Time
Task D - Preparing Boxes
User vain0
Language Rust (1.15.1)
Score 400
Code Size 2687 Byte
Status AC
Exec Time 28 ms
Memory 14344 KB

Judge Result

Set Name All Sample
Score / Max Score 400 / 400 0 / 0
Status
AC × 18
AC × 2
Set Name Test Cases
All sample_01, sample_02, testcase_0, testcase_1, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_2, testcase_3, testcase_4, testcase_5, testcase_6, testcase_7, testcase_8, testcase_9, testcase_add0
Sample sample_01, sample_02
Case Name Status Exec Time Memory
sample_01 AC 2 ms 4352 KB
sample_02 AC 2 ms 4352 KB
testcase_0 AC 11 ms 8572 KB
testcase_1 AC 21 ms 12536 KB
testcase_10 AC 13 ms 8444 KB
testcase_11 AC 8 ms 6396 KB
testcase_12 AC 4 ms 4352 KB
testcase_13 AC 2 ms 4352 KB
testcase_14 AC 2 ms 4352 KB
testcase_2 AC 8 ms 6524 KB
testcase_3 AC 13 ms 8700 KB
testcase_4 AC 14 ms 8700 KB
testcase_5 AC 26 ms 13104 KB
testcase_6 AC 17 ms 10492 KB
testcase_7 AC 28 ms 13232 KB
testcase_8 AC 13 ms 8444 KB
testcase_9 AC 3 ms 4352 KB
testcase_add0 AC 26 ms 14344 KB


2025-04-08 (Tue)
19:57:39 +00:00