Submission #1167301
Source Code Expand
use std::io::{BufRead, Write, stdin, stdout}; fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) { let mut s = String::new(); input.read_line(&mut s).unwrap(); let x = s.trim().parse::<i64>().unwrap(); let mut result = ((x * 2) as f64).sqrt().floor() as i64; if result * (result + 1) / 2 < x { result += 1; } writeln!(output, "{}", result).unwrap(); } fn main() { let stdin = stdin(); let stdout = stdout(); solve(stdin.lock(), stdout.lock()); } #[cfg(test)] mod tests { fn test(input: &str, output: &str) { let mut v = Vec::<u8>::new(); ::solve(input.as_bytes(), &mut v); assert_eq!(String::from_utf8(v).unwrap(), output); } #[test] fn case1() { test("6\n", "3\n"); } #[test] fn case2() { test("2\n", "2\n"); } #[test] fn case3() { test("11\n", "5\n"); } }
Submission Info
Submission Time | |
---|---|
Task | C - Go Home |
User | tatsuyuki |
Language | Rust (1.15.1) |
Score | 200 |
Code Size | 949 Byte |
Status | AC |
Exec Time | 2 ms |
Memory | 4352 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 200 / 200 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 2 ms | 4352 KB |
0_001.txt | AC | 2 ms | 4352 KB |
0_002.txt | AC | 2 ms | 4352 KB |
1_003.txt | AC | 2 ms | 4352 KB |
1_004.txt | AC | 2 ms | 4352 KB |
1_005.txt | AC | 2 ms | 4352 KB |
1_006.txt | AC | 2 ms | 4352 KB |
1_007.txt | AC | 2 ms | 4352 KB |
1_008.txt | AC | 2 ms | 4352 KB |
1_009.txt | AC | 2 ms | 4352 KB |
1_010.txt | AC | 2 ms | 4352 KB |
1_011.txt | AC | 2 ms | 4352 KB |
1_012.txt | AC | 2 ms | 4352 KB |
1_013.txt | AC | 2 ms | 4352 KB |
1_014.txt | AC | 2 ms | 4352 KB |
1_015.txt | AC | 2 ms | 4352 KB |
1_016.txt | AC | 2 ms | 4352 KB |
1_017.txt | AC | 2 ms | 4352 KB |