Submission #3367083
Source Code Expand
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
(source = $s:expr, $($r:tt)*) => {
let mut iter = $s.split_whitespace();
input_inner!{iter, $($r)*}
};
($($r:tt)*) => {
let mut s = {
use std::io::Read;
let mut s = String::new();
std::io::stdin().read_to_string(&mut s).unwrap();
s
};
let mut iter = s.split_whitespace();
input_inner!{iter, $($r)*}
};
}
macro_rules! input_inner {
($iter:expr) => {};
($iter:expr, ) => {};
($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
let $var = read_value!($iter, $t);
input_inner!{$iter $($r)*}
};
}
macro_rules! read_value {
($iter:expr, ( $($t:tt),* )) => {
( $(read_value!($iter, $t)),* )
};
($iter:expr, [ $t:tt ; $len:expr ]) => {
(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
};
($iter:expr, chars) => {
read_value!($iter, String).chars().collect::<Vec<char>>()
};
($iter:expr, usize1) => {
read_value!($iter, usize) - 1
};
($iter:expr, $t:ty) => {
$iter.next().unwrap().parse::<$t>().expect("Parse error")
};
}
use std::cmp;
fn main() {
input!(n: usize, m: usize, x: [usize; n]);
let mut remainder = vec![vec![]; m];
for &x in x.iter() {
let r = x % m;
remainder[r].push(x);
}
let mut ans = 0;
for i in 0..m {
if i == 0 || i * 2 == m {
ans += remainder[i].len() / 2;
} else if m - i < i {
break;
} else {
let j = m - i;
let len_i = remainder[i].len();
let len_j = remainder[j].len();
ans += cmp::min(len_i, len_j);
let t = if len_i > len_j { i } else { j };
remainder[t].sort();
let mut pair = 0;
let mut i = 1;
while i < remainder[t].len() {
if remainder[t][i - 1] == remainder[t][i] {
pair += 1;
i += 2;
} else {
i += 1;
}
}
let remain = cmp::max(len_i, len_j) - cmp::min(len_i, len_j);
ans += cmp::min(remain / 2, pair);
}
}
println!("{}", ans);
}
Submission Info
Submission Time
2018-10-08 14:36:03+0900
Task
D - Pair Cards
User
kenkoooo
Language
Rust (1.15.1)
Score
700
Code Size
2455 Byte
Status
AC
Exec Time
16 ms
Memory
12540 KB
Compile Error
warning: variable does not need to be mutable, #[warn(unused_mut)] on by default
--> ./Main.rs:9:13
|
9 | let mut s = {
| ^^^^^
...
55 | input!(n: usize, m: usize, x: [usize; n]);
| ------------------------------------------ in this macro invocation
Judge Result
Set Name
sample
all
Score / Max Score
0 / 0
700 / 700
Status
Set Name
Test Cases
sample
sample-01.txt, sample-02.txt
all
sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, sample-01.txt, sample-02.txt
Case Name
Status
Exec Time
Memory
01-01.txt
AC
2 ms
4352 KB
01-02.txt
AC
8 ms
8444 KB
01-03.txt
AC
9 ms
8444 KB
01-04.txt
AC
11 ms
8444 KB
01-05.txt
AC
10 ms
8444 KB
01-06.txt
AC
11 ms
8444 KB
01-07.txt
AC
10 ms
6396 KB
01-08.txt
AC
10 ms
6396 KB
01-09.txt
AC
10 ms
6396 KB
01-10.txt
AC
13 ms
8444 KB
01-11.txt
AC
16 ms
12540 KB
01-12.txt
AC
9 ms
8444 KB
01-13.txt
AC
10 ms
10492 KB
01-14.txt
AC
9 ms
8444 KB
01-15.txt
AC
11 ms
8444 KB
01-16.txt
AC
11 ms
8444 KB
01-17.txt
AC
10 ms
6396 KB
01-18.txt
AC
11 ms
8444 KB
01-19.txt
AC
11 ms
6396 KB
01-20.txt
AC
16 ms
12540 KB
01-21.txt
AC
9 ms
8444 KB
01-22.txt
AC
10 ms
6396 KB
01-23.txt
AC
11 ms
8444 KB
01-24.txt
AC
10 ms
6396 KB
01-25.txt
AC
11 ms
8444 KB
01-26.txt
AC
12 ms
10492 KB
01-27.txt
AC
10 ms
10492 KB
01-28.txt
AC
4 ms
8444 KB
01-29.txt
AC
2 ms
4352 KB
01-30.txt
AC
4 ms
8444 KB
sample-01.txt
AC
2 ms
4352 KB
sample-02.txt
AC
2 ms
4352 KB