結果
| 問題 | No.1352 Three Coins |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-17 18:05:20 |
| 言語 | Rust (1.92.0 + proconio + num) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 6,883 bytes |
| 記録 | |
| コンパイル時間 | 15,457 ms |
| コンパイル使用メモリ | 378,312 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-29 22:48:05 |
| 合計ジャッジ時間 | 18,666 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 1 |
| other | AC * 11 WA * 23 |
ソースコード
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
($($r:tt)*) => {
let stdin = std::io::stdin();
let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
let mut next = move || -> String{
bytes.by_ref().map(|r|r.unwrap() as char)
.skip_while(|c|c.is_whitespace())
.take_while(|c|!c.is_whitespace())
.collect()
};
input_inner!{next, $($r)*}
};
}
macro_rules! input_inner {
($next:expr) => {};
($next:expr, ) => {};
($next:expr, $var:ident : $t:tt $($r:tt)*) => {
let $var = read_value!($next, $t);
input_inner!{$next $($r)*}
};
}
macro_rules! read_value {
($next:expr, [graph1; $len:expr]) => {{
let mut g = vec![vec![]; $len];
let ab = read_value!($next, [(usize1, usize1)]);
for (a, b) in ab {
g[a].push(b);
g[b].push(a);
}
g
}};
($next:expr, ( $($t:tt),* )) => {
( $(read_value!($next, $t)),* )
};
($next:expr, [ $t:tt ; $len:expr ]) => {
(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
};
($next:expr, chars) => {
read_value!($next, String).chars().collect::<Vec<char>>()
};
($next:expr, usize1) => (read_value!($next, usize) - 1);
($next:expr, [ $t:tt ]) => {{
let len = read_value!($next, usize);
read_value!($next, [$t; len])
}};
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}
trait Change {
fn chmax(&mut self, x: Self);
fn chmin(&mut self, x: Self);
}
impl<T: PartialOrd> Change for T {
fn chmax(&mut self, x: T) {
if *self < x { *self = x; }
}
fn chmin(&mut self, x: T) {
if *self > x { *self = x; }
}
}
#[allow(unused)]
macro_rules! debug {
($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}
fn gcd(x: usize, y: usize) -> usize {
if y == 0 {
x
} else {
gcd(y, x % y)
}
}
// Verified by https://atcoder.jp/contests/arc084/submissions/3935443
#[derive(Clone)]
struct BitSet {
size: usize,
buf: Vec<usize>,
}
impl BitSet {
// size should be a multiple of bit-size of usize.
fn new(size: usize) -> Self {
let w = 8 * std::mem::size_of::<usize>();
assert_eq!(size & (w - 1), 0);
let count = size / w;
BitSet {
size: size,
buf: vec![0; count],
}
}
#[allow(unused)]
fn set(&mut self, idx: usize, val: bool) {
debug_assert!(idx < self.size);
let w = 8 * std::mem::size_of::<usize>();
let idx0 = idx / w;
let idx1 = idx & (w - 1);
if val {
self.buf[idx0] |= 1 << idx1;
} else {
self.buf[idx0] &= !(1 << idx1);
}
}
#[allow(unused)]
fn get(&self, idx: usize) -> bool {
let w = 8 * std::mem::size_of::<usize>();
debug_assert!(idx < self.size);
let idx0 = idx / w;
let idx1 = idx & (w - 1);
(self.buf[idx0] >> idx1 & 1) == 1
}
#[allow(unused)]
fn shl(&self, val: usize) -> Self {
if val >= self.size { return Self::new(self.size); }
let w = 8 * std::mem::size_of::<usize>();
let count = self.size / w;
let sh0 = val / w;
let sh1 = val & (w - 1);
let mut ans = Self::new(self.size);
if sh1 == 0 {
for i in 0 .. count - sh0 {
ans.buf[i + sh0] = self.buf[i];
}
} else {
ans.buf[sh0] = self.buf[0] << sh1;
for i in 1 .. count - sh0 {
ans.buf[i + sh0] = self.buf[i] << sh1
| self.buf[i - 1] >> (w - sh1);
}
}
ans
}
// Not verified
#[allow(unused)]
fn shr(&self, val: usize) -> Self {
if val >= self.size { return Self::new(self.size); }
let w = 8 * std::mem::size_of::<usize>();
let count = self.size / w;
let sh0 = val / w;
let sh1 = val & (w - 1);
let mut ans = Self::new(self.size);
if sh1 == 0 {
for i in 0 .. count - sh0 {
ans.buf[i] = self.buf[i + sh0];
}
} else {
for i in 0 .. count - sh0 - 1 {
ans.buf[i] = self.buf[i + sh0] >> sh1
| self.buf[i + sh0 + 1] << (w - sh1);
}
ans.buf[self.size - sh0 - 1] = self.buf[self.size - 1] >> sh1;
}
ans
}
#[allow(unused)]
fn msb(&self) -> Option<usize> {
let w = 8 * std::mem::size_of::<usize>();
let count = self.size / w;
for i in (0 .. count).rev() {
let v = self.buf[i];
if v != 0 {
return Some(w * i + w - 1 - v.leading_zeros() as usize);
}
}
None
}
}
// TODO reference is not allowed as rhs
impl std::ops::BitXorAssign for BitSet {
fn bitxor_assign(&mut self, other: BitSet) {
debug_assert_eq!(self.size, other.size);
for i in 0 .. self.buf.len() {
self.buf[i] ^= other.buf[i];
}
}
}
impl std::ops::BitOrAssign for BitSet {
fn bitor_assign(&mut self, other: BitSet) {
debug_assert_eq!(self.size, other.size);
for i in 0 .. self.buf.len() {
self.buf[i] |= other.buf[i];
}
}
}
fn solve() {
let out = std::io::stdout();
let mut out = BufWriter::new(out.lock());
macro_rules! puts {
($($format:tt)*) => (let _ = write!(out,$($format)*););
}
#[allow(unused)]
macro_rules! putvec {
($v:expr) => {
for i in 0..$v.len() {
puts!("{}{}", $v[i], if i + 1 == $v.len() {"\n"} else {" "});
}
}
}
input! {
a: usize, b: usize, c: usize,
}
let g = gcd(gcd(a, b), c);
if g != 1 {
puts!("INF\n");
return;
}
const W: usize = 2 * 2000 * 2000;
let mut bs = BitSet::new(W);
bs.set(0, true);
let abc = vec![a, b, c];
for x in abc {
for i in 0..W - x {
if !bs.get(i) {
continue;
}
bs.set(i + x, true);
}
}
let mut ma = 0;
for i in 0..W {
if !bs.get(i) {
ma = i;
}
}
puts!("{}\n", ma);
}
fn main() {
// In order to avoid potential stack overflow, spawn a new thread.
let stack_size = 104_857_600; // 100 MB
let thd = std::thread::Builder::new().stack_size(stack_size);
thd.spawn(|| solve()).unwrap().join().unwrap();
}