Submission #1575502


Source Code Expand

Copy
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let (h, w): (usize, usize) = read();
    let n: usize = read();
    let a: Vec<usize> = readnc();

    let mut positions: Vec<(usize, usize)> = vec![];
    for i in 0..h {
        if i % 2 == 0 {
            for j in 0..w {
                positions.push((i, j));
            }
        } else {
            for j in (0..w).rev() {
                positions.push((i, j));
            }
        }
    }

    let mut ans: Vec<Vec<usize>> = vec![vec![0; w]; h];
    let mut idx = 0;
    for i in 0..n {
        for j in 0..a[i] {
            let (y, x) = positions[idx];
            ans[y][x] = i+1;
            idx += 1
        }
    }

    for i in 0..h {
        for j in 0..w {
            if j >= 1 {
                print!(" ");
            }
            print!("{}", ans[i][j]);
        }
        println!();
    }
}

Submission Info

Submission Time
Task D - Grid Coloring
User hamadu
Language Rust (1.15.1)
Score 400
Code Size 2188 Byte
Status AC
Exec Time 5 ms
Memory 4352 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 25
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt
Case Name Status Exec Time Memory
0_00.txt AC 2 ms 4352 KB
0_01.txt AC 2 ms 4352 KB
0_02.txt AC 2 ms 4352 KB
1_00.txt AC 2 ms 4352 KB
1_01.txt AC 2 ms 4352 KB
1_02.txt AC 2 ms 4352 KB
1_03.txt AC 4 ms 4352 KB
1_04.txt AC 5 ms 4352 KB
1_05.txt AC 5 ms 4352 KB
1_06.txt AC 4 ms 4352 KB
1_07.txt AC 2 ms 4352 KB
1_08.txt AC 2 ms 4352 KB
1_09.txt AC 2 ms 4352 KB
1_10.txt AC 2 ms 4352 KB
1_11.txt AC 2 ms 4352 KB
1_12.txt AC 2 ms 4352 KB
1_13.txt AC 4 ms 4352 KB
1_14.txt AC 2 ms 4352 KB
1_15.txt AC 2 ms 4352 KB
1_16.txt AC 2 ms 4352 KB
1_17.txt AC 4 ms 4352 KB
1_18.txt AC 2 ms 4352 KB
1_19.txt AC 2 ms 4352 KB
1_20.txt AC 2 ms 4352 KB
1_21.txt AC 2 ms 4352 KB