제출 #1344048

#제출 시각아이디문제언어결과실행 시간메모리
1344048pccCircle Passing (EGOI24_circlepassing)C++20
컴파일 에러
0 ms0 KiB
use std::fmt::Debug;
use std::io::{self, Read};
use std::str::{FromStr, SplitWhitespace};

struct IoContent {
    s: String,
}
impl IoContent {
    fn new() -> IoContent {
        let mut s = String::new();
        let _ = io::stdin().read_to_string(&mut s);
        IoContent { s: s }
    }
}

struct IoReader<'a> {
    inp: SplitWhitespace<'a>,
}

impl IoReader<'_> {
    fn new<'a>(inp: &'a IoContent) -> IoReader<'a> {
        IoReader {
            inp: inp.s.split_whitespace(),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        <T as FromStr>::Err: Debug,
    {
        self.inp.next().unwrap().parse::<T>().unwrap()
    }
}

fn dis(mut a: u32, mut b: u32, n: u32) -> u32{
    if a > b {
        std::mem::swap(&mut a, &mut b);
    }
    let d = b-a;
    std::cmp::min(d, n*2-d)
}

fn rev(x: u32, n: u32) -> u32 {
    return if x >= n {
        x - n
    } else {
        x + n
    };
}

fn solve(inp: &mut IoReader, n: u32, v: &Vec<u32>) -> String {
    let x: u32 = inp.read();
    let y: u32 = inp.read();
    let mut ans = dis(x, y, n);
    let p = match v.binary_search(&x) {
        Ok(x) => x,
        Err(x) => x,
    } % v.len();
    ans = std::cmp::min(ans, dis(v[p], x, n) + dis(rev(v[p], n), y, n)+1);
    let p = (p + v.len() - 1) % v.len();
    ans = std::cmp::min(ans, dis(v[p], x, n) + dis(rev(v[p], n), y, n)+1);
    return ans.to_string();
}

fn main() {
    let inp = IoContent::new();
    let mut inp = IoReader::new(&inp);
    let n: u32 = inp.read();
    let m: usize = inp.read();
    let q: usize = inp.read();
    let mut v: Vec<u32> = vec![0; m*2];
    for i in 0..m {
        v[i] = inp.read();
        v[i+m] = v[i] + n;
    }
    let mut ans = String::new();
    for _ in 0..q {
        ans += &solve(&mut inp, n, &v);
        ans.push('\n');
    }
    print!("{ans}");
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp:16:17: warning: missing terminating ' character
   16 | struct IoReader<'a> {
      |                 ^
Main.cpp:16:17: error: missing terminating ' character
   16 | struct IoReader<'a> {
      |                 ^~~~~
Main.cpp:17:26: warning: missing terminating ' character
   17 |     inp: SplitWhitespace<'a>,
      |                          ^
Main.cpp:17:26: error: missing terminating ' character
   17 |     inp: SplitWhitespace<'a>,
      |                          ^~~~
Main.cpp:20:15: warning: missing terminating ' character
   20 | impl IoReader<'_> {
      |               ^
Main.cpp:20:15: error: missing terminating ' character
   20 | impl IoReader<'_> {
      |               ^~~~~
Main.cpp:21:12: warning: character constant too long for its type
   21 |     fn new<'a>(inp: &'a IoContent) -> IoReader<'a> {
      |            ^~~~~~~~~~~~
Main.cpp:21:48: warning: missing terminating ' character
   21 |     fn new<'a>(inp: &'a IoContent) -> IoReader<'a> {
      |                                                ^
Main.cpp:21:48: error: missing terminating ' character
   21 |     fn new<'a>(inp: &'a IoContent) -> IoReader<'a> {
      |                                                ^~~~~
Main.cpp:72:14: error: too many decimal points in number
   72 |     for i in 0..m {
      |              ^~~~
Main.cpp:77:14: error: too many decimal points in number
   77 |     for _ in 0..q {
      |              ^~~~
Main.cpp:1:1: error: 'use' does not name a type
    1 | use std::fmt::Debug;
      | ^~~
Main.cpp:2:1: error: 'use' does not name a type
    2 | use std::io::{self, Read};
      | ^~~
Main.cpp:3:1: error: 'use' does not name a type
    3 | use std::str::{FromStr, SplitWhitespace};
      | ^~~
Main.cpp:6:5: error: 's' does not name a type
    6 |     s: String,
      |     ^
Main.cpp:8:6: error: expected initializer before 'IoContent'
    8 | impl IoContent {
      |      ^~~~~~~~~
Main.cpp:16:8: error: 'IoReader' is not a class template
   16 | struct IoReader<'a> {
      |        ^~~~~~~~
Main.cpp:17:5: error: 'inp' was not declared in this scope; did you mean 'int'?
   17 |     inp: SplitWhitespace<'a>,
      |     ^~~
      |     int
Main.cpp:18:1: error: expected unqualified-id before '}' token
   18 | }
      | ^
Main.cpp:18:1: error: expected declaration before '}' token
Main.cpp:20:1: error: 'impl' does not name a type
   20 | impl IoReader<'_> {
      | ^~~~
Main.cpp:25:5: error: expected declaration before '}' token
   25 |     }
      |     ^
Main.cpp:26:5: error: 'fn' does not name a type
   26 |     fn read<T>(&mut self) -> T
      |     ^~
Main.cpp:33:1: error: expected declaration before '}' token
   33 | }
      | ^
Main.cpp:35:1: error: 'fn' does not name a type
   35 | fn dis(mut a: u32, mut b: u32, n: u32) -> u32{
      | ^~
Main.cpp:43:1: error: 'fn' does not name a type
   43 | fn rev(x: u32, n: u32) -> u32 {
      | ^~
Main.cpp:51:1: error: 'fn' does not name a type
   51 | fn solve(inp: &mut IoReader, n: u32, v: &Vec<u32>) -> String {
      | ^~
Main.cpp:65:1: error: 'fn' does not name a type
   65 | fn main() {
      | ^~