提出 #677448


ソースコード 拡げる

Copy
use std::io;
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

const INF: i32 = 1_000_000_000;
fn dist(x: i32, y: i32) -> i32 { x.abs() + y.abs() }

fn main() {
  let mut sc = Scanner::new();
  let s: String = sc.cin();
  let t: usize = sc.cin();
  let mut x = 0; let mut y = 0;
  let mut n = 0;
  for c in s.chars() {
      match c {
          'U' => x += 1,
          'D' => x -= 1,
          'L' => y -= 1,
          'R' => y += 1,
          _ => n += 1,
      }
  }

  let mut mn = INF;
  let mut mx = 0;

  for d in 0..(n+1) {
      { let r = dist(x - n + d, y - d); mn = min(mn, r); mx = max(mx, r); }
      { let r = dist(x - n + d, y + d); mn = min(mn, r); mx = max(mx, r); }
      { let r = dist(x + n - d, y - d); mn = min(mn, r); mx = max(mx, r); }
      { let r = dist(x + n - d, y + d); mn = min(mn, r); mx = max(mx, r); }
  }

  if dist(x, y) <= n {
      mn = if (n - dist(x, y)) % 2 == 0 { 0 } else { 1 }
  }

  println!("{}", if t==1 { mx } else { mn });

}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
    fn get_char(&mut self) -> char {
        self.reserve();
        let head = self.buffer[0].chars().nth(0).unwrap();
        let tail = String::from( &self.buffer[0][1..] );
        if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }
        head
    }
}

提出情報

提出日時
問題 B - ドローン
ユーザ cympfh
言語 Rust (1.15.1)
得点 101
コード長 2083 Byte
結果
実行時間 9 ms
メモリ 636 KB

コンパイルエラー

./Main.rs:4:25: 4:35 warning: unused import, #[warn(unused_imports)] on by default
./Main.rs:4 use std::collections::{ BinaryHeap, VecDeque };
                                    ^~~~~~~~~~

ジャッジ結果

セット名 得点 / 配点 テストケース
Sample 0 / 0 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 00_example_04.txt
Subtask1 100 / 100 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 20_no_question_01.txt, 20_no_question_02.txt, 20_no_question_03.txt, 20_no_question_04.txt, 30_max_01.txt, 30_max_02.txt, 30_max_03.txt, 30_max_04.txt, 40_corner_01.txt, 40_corner_02.txt, 40_corner_03.txt, 40_corner_04.txt
All 1 / 1 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 00_example_04.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 20_no_question_01.txt, 20_no_question_02.txt, 20_no_question_03.txt, 20_no_question_04.txt, 30_max_01.txt, 30_max_02.txt, 30_max_03.txt, 30_max_04.txt, 40_corner_01.txt, 40_corner_02.txt, 40_corner_03.txt, 40_corner_04.txt, 50_hand_01.txt, 50_hand_02.txt, 50_hand_03.txt, 60_rand_01.txt, 60_rand_02.txt, 60_rand_03.txt, 60_rand_04.txt, 70_no_ques_01.txt, 70_no_ques_02.txt, 70_no_ques_03.txt, 70_no_ques_04.txt, 80_max_01.txt, 80_max_02.txt, 80_max_03.txt, 80_max_04.txt, 90_corner_01.txt, 90_corner_02.txt, 90_corner_03.txt, 90_corner_04.txt
ケース名 結果 実行時間 メモリ
00_example_01.txt 4 ms 380 KB
00_example_02.txt 4 ms 380 KB
00_example_03.txt 4 ms 380 KB
00_example_04.txt 4 ms 380 KB
10_rand_01.txt 5 ms 380 KB
10_rand_02.txt 4 ms 380 KB
10_rand_03.txt 4 ms 380 KB
10_rand_04.txt 4 ms 380 KB
20_no_question_01.txt 5 ms 380 KB
20_no_question_02.txt 4 ms 380 KB
20_no_question_03.txt 4 ms 380 KB
20_no_question_04.txt 4 ms 380 KB
30_max_01.txt 7 ms 636 KB
30_max_02.txt 7 ms 636 KB
30_max_03.txt 7 ms 636 KB
30_max_04.txt 7 ms 636 KB
40_corner_01.txt 7 ms 636 KB
40_corner_02.txt 7 ms 636 KB
40_corner_03.txt 7 ms 636 KB
40_corner_04.txt 7 ms 636 KB
50_hand_01.txt 4 ms 380 KB
50_hand_02.txt 4 ms 380 KB
50_hand_03.txt 4 ms 380 KB
60_rand_01.txt 4 ms 380 KB
60_rand_02.txt 4 ms 380 KB
60_rand_03.txt 4 ms 380 KB
60_rand_04.txt 5 ms 380 KB
70_no_ques_01.txt 6 ms 380 KB
70_no_ques_02.txt 4 ms 380 KB
70_no_ques_03.txt 4 ms 380 KB
70_no_ques_04.txt 4 ms 380 KB
80_max_01.txt 7 ms 636 KB
80_max_02.txt 7 ms 636 KB
80_max_03.txt 7 ms 636 KB
80_max_04.txt 7 ms 636 KB
90_corner_01.txt 7 ms 636 KB
90_corner_02.txt 7 ms 636 KB
90_corner_03.txt 9 ms 636 KB
90_corner_04.txt 7 ms 636 KB