Submission #1662382


Source Code Expand

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 Info

Submission Time
Task C - Scc Puzzle
User ir5
Language Rust (1.15.1)
Score 300
Code Size 1249 Byte
Status AC
Exec Time 2 ms
Memory 4352 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 9
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt
All 00_example_01.txt, 00_example_02.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt
Case Name Status Exec Time Memory
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