結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-06-09 10:12:52 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 966 bytes |
| コンパイル時間 | 13,126 ms |
| コンパイル使用メモリ | 401,748 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-21 05:27:56 |
| 合計ジャッジ時間 | 14,658 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
use std::io::Read;
fn main(){
let mut input = "".to_owned();
std::io::stdin().read_to_string(&mut input).unwrap();
let mut input = input.split_ascii_whitespace();
macro_rules! read(($ty:ty) => (input.next().unwrap().parse::<$ty>().unwrap()));
let n=read!(usize);
let mut list=vec![!0;n];
for i in 0..n{
list[i]=i+1;
}
let mut dist=vec![0;n];
dist[0]=1;
let mut que=std::collections::VecDeque::new();
que.push_back(0);
while let Some(pos)=que.pop_front(){
if pos==n-1{
println!("{}",dist[pos]);
std::process::exit(0);
}
else{
let r=(pos+1).count_ones();
for dir in [1,-1]{
let next=pos+(dir*r as i64) as usize;
if next<n && dist[next]==0{
dist[next]=dist[pos]+1;
que.push_back(next);
}
}
}
}
println!("-1");
}