AtCoder Regular Contest 069

Submission #1662382

Source codeソースコード

use std::io::{stdin, Read, StdinLock};
use std::str::*;
use std::cmp;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main(){
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    while let Some(s) = sc.read1::<i64>() {
        let c: i64 = sc.read();

        // (s, c) -> (s + a, c - 2a) -> min(s + a, (c - 2a) // 2)
        // s + a = (c - 2a) // 2 <=> a = c/4 - s/2
        let mut res: i64 = 0;
        for b in -10..10 {
            let mut a = c / 4 - s / 2 + b;
            a = cmp::max(a, 0);
            a = cmp::min(a, c / 2);
            let cand = cmp::min(s + a, (c - 2 * a) / 2);
            res = cmp::max(res, cand);
        }
        println!("{}", res);
    }
}

Submission

Task問題 C - Scc Puzzle
User nameユーザ名 もふ
Created time投稿日時
Language言語 Rust (1.15.1)
Status状態 AC
Score得点 300
Source lengthソースコード長 1249 Byte
File nameファイル名
Exec time実行時間 2 ms
Memory usageメモリ使用量 4352 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - 00_example_01.txt,00_example_02.txt
All 300 / 300 00_example_01.txt,00_example_02.txt,01.txt,02.txt,03.txt,04.txt,05.txt,06.txt,07.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_example_01.txt AC 2 ms 4352 KB
00_example_02.txt AC 2 ms 4352 KB
01.txt AC 2 ms 4352 KB
02.txt AC 2 ms 4352 KB
03.txt AC 2 ms 4352 KB
04.txt AC 2 ms 4352 KB
05.txt AC 2 ms 4352 KB
06.txt AC 2 ms 4352 KB
07.txt AC 2 ms 4352 KB