Submission #2366898
Source Code Expand
use std::collections::{BTreeMap, BTreeSet};
fn main() {
let mut sc = Scanner::new();
let x: i64 = sc.read();
let y: i64 = sc.read();
if (x - y).abs() <= 1 {
println!("Brown");
} else {
println!("Alice");
}
}
fn exp() {
let mut map = BTreeMap::new();
for z in 0..10000 {
for x in 0..(z + 1) {
let y = z - x;
if y < x { continue; }
if grundy(x, y, &mut map) == 0 {
println!("{} {} {}", x, y, y - x);
}
}
}
}
fn grundy(x: usize, y: usize, map: &mut BTreeMap<(usize, usize), usize>) -> usize {
let (x, y) = norm(x, y);
if !map.contains_key(&(x, y)) {
let mut set = BTreeSet::new();
for i in 1..(x / 2 + 1) {
set.insert(grundy(x - 2 * i, y + i, map));
}
for i in 1..(y / 2 + 1) {
set.insert(grundy(x + i, y - 2 * i, map));
}
let mut g = 0;
loop {
if set.contains(&g) {
g += 1;
} else {
break;
}
}
map.insert((x, y), g);
}
let g: usize = *map.get(&(x, y)).unwrap();
return g;
}
fn norm(x: usize, y: usize) -> (usize, usize) {
if x >= y { (y, x) } else { (x, y) }
}
struct Scanner {
ptr: usize,
length: usize,
buf: Vec<u8>,
small_cache: Vec<u8>,
}
impl Scanner {
fn new() -> Scanner {
Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024] }
}
fn load(&mut self) {
use std::io::Read;
let mut s = std::io::stdin();
self.length = s.read(&mut self.buf).unwrap();
}
fn byte(&mut self) -> u8 {
if self.ptr >= self.length {
self.ptr = 0;
self.load();
if self.length == 0 {
self.buf[0] = b'\n';
self.length = 1;
}
}
self.ptr += 1;
return self.buf[self.ptr - 1];
}
fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' }
fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, {
let mut b = self.byte();
while Scanner::is_space(b) {
b = self.byte();
}
for pos in 0..self.small_cache.len() {
self.small_cache[pos] = b;
b = self.byte();
if Scanner::is_space(b) {
return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]).parse().unwrap();
}
}
let mut v = self.small_cache.clone();
while !Scanner::is_space(b) {
v.push(b);
b = self.byte();
}
return String::from_utf8_lossy(&v).parse().unwrap();
}
}
Submission Info
Submission Time |
|
Task |
D - Alice&Brown |
User |
kenkoooo |
Language |
Rust (1.15.1) |
Score |
500 |
Code Size |
2882 Byte |
Status |
AC |
Exec Time |
2 ms |
Memory |
4352 KB |
Compile Error
warning: function is never used: `exp`, #[warn(dead_code)] on by default
--> ./Main.rs:15:1
|
15 | fn exp() {
| ^
warning: function is never used: `grundy`, #[warn(dead_code)] on by default
--> ./Main.rs:28:1
|
28 | fn grundy(x: usize, y: usize, map: &mut BTreeMap<(usize, usize), usize>) -> usize {
| ^
warning: function is never used: `norm`, #[warn(dead_code)] on by default
--> ./Main.rs:56:1
|
56 | fn norm(x: usize, y: usize) -> (usize, usize) {
| _^ starting here...
57 | | if x >= y { (y, x) } else { (x, y) }
58 | | }
| |_^ ...ending here
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00-00.txt, 00-01.txt, 00-02.txt, 00-03.txt |
All |
00-00.txt, 00-01.txt, 00-02.txt, 00-03.txt, 01-00.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt |
Case Name |
Status |
Exec Time |
Memory |
00-00.txt |
AC |
2 ms |
4352 KB |
00-01.txt |
AC |
2 ms |
4352 KB |
00-02.txt |
AC |
2 ms |
4352 KB |
00-03.txt |
AC |
2 ms |
4352 KB |
01-00.txt |
AC |
2 ms |
4352 KB |
01-01.txt |
AC |
2 ms |
4352 KB |
01-02.txt |
AC |
2 ms |
4352 KB |
01-03.txt |
AC |
2 ms |
4352 KB |
01-04.txt |
AC |
2 ms |
4352 KB |
01-05.txt |
AC |
2 ms |
4352 KB |
01-06.txt |
AC |
2 ms |
4352 KB |
01-07.txt |
AC |
2 ms |
4352 KB |
01-08.txt |
AC |
2 ms |
4352 KB |
01-09.txt |
AC |
2 ms |
4352 KB |
01-10.txt |
AC |
2 ms |
4352 KB |
01-11.txt |
AC |
2 ms |
4352 KB |
01-12.txt |
AC |
2 ms |
4352 KB |
01-13.txt |
AC |
2 ms |
4352 KB |
01-14.txt |
AC |
2 ms |
4352 KB |
01-15.txt |
AC |
2 ms |
4352 KB |
01-16.txt |
AC |
2 ms |
4352 KB |
01-17.txt |
AC |
2 ms |
4352 KB |
01-18.txt |
AC |
2 ms |
4352 KB |
01-19.txt |
AC |
2 ms |
4352 KB |