Submission #1561473
Source Code Expand
use std::io;
use std::io::{Read, BufReader};
use std::cmp;
macro_rules! read {
( $( $t:ty ),* ) => {
{
let mut buf = String::new();
io::stdin().read_line(&mut buf);
let mut sp = buf.trim().split(" ");
($(
{
sp.next().unwrap().parse::<$t>().unwrap()
},
)*)
}
}
}
macro_rules! read_vec {
($t:ty) => {
{
let mut buf = String::new();
io::stdin().read_line(&mut buf);
let mut sp = buf.trim().split(" ");
let mut ret = vec![];
for s in sp {
ret.push(s.parse::<$t>().unwrap());
}
ret
}
}
}
fn trunc((low, hi, app): (i64, i64, i64), x: i64) -> (i64, i64, i64) {
let (mut low, mut hi, mut app) = (low, hi, app);
hi = cmp::min(hi, x);
low = cmp::max(low, 0);
low = cmp::min(low, x);
hi = cmp::max(hi, 0);
(low, hi, app)
}
fn eval((low, hi, app): (i64, i64, i64), x: i64) -> i64 {
cmp::min(hi, cmp::max(low, app + x))
}
fn main() {
let (x,) = read!(i64);
let (k,) = read!(usize);
let rs = read_vec!(i64);
let (q,) = read!(usize);
let mut dir = 0; // 0: decl, 1: incl
let (mut low, mut hi, mut app) = (0i64, x, 0i64);
let mut pos = 0;
let mut last_app = 0i64;
for _ in 0..q {
let (t, a) = read!(i64, i64);
while pos < k && rs[pos] <= t {
let df = if dir == 0 { -(rs[pos] - last_app) } else { rs[pos] - last_app };
low += df;
hi += df;
app += df;
let a = trunc((low, hi, app), x);
low = a.0;
hi = a.1;
app = a.2;
dir = 1 - dir;
last_app = rs[pos];
pos += 1;
}
let df = if dir == 0 { -(t - last_app) } else { t - last_app };
let (low2, hi2, app2) = trunc((low + df, hi + df, app + df), x);
let ans = eval((low2, hi2, app2), a);
println!("{}", ans);
}
}
Submission Info
Submission Time
2017-09-02 21:37:23+0900
Task
F - Sandglass
User
semiexp
Language
Rust (1.15.1)
Score
700
Code Size
2149 Byte
Status
AC
Exec Time
221 ms
Memory
7292 KB
Compile Error
warning: unused imports: `BufReader`, `Read`, #[warn(unused_imports)] on by default
--> ./Main.rs:2:15
|
2 | use std::io::{Read, BufReader};
| ^^^^ ^^^^^^^^^
warning: variable does not need to be mutable, #[warn(unused_mut)] on by default
--> ./Main.rs:35:27
|
35 | let (mut low, mut hi, mut app) = (low, hi, app);
| ^^^^^^^
warning: unused result which must be used, #[warn(unused_must_use)] on by default
--> ./Main.rs:9:13
|
9 | io::stdin().read_line(&mut buf);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
48 | let (x,) = read!(i64);
| ---------- in this macro invocation
warning: unused result which must be used, #[warn(unused_must_use)] on by default
--> ./Main.rs:9:13
|
9 | io::stdin().read_line(&mut buf);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
49 | let (k,) = read!(usize);
| ------------ in this macro invocation
warning: unused result whic...
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
700 / 700
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, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt, 1_033.txt, 1_034.txt, 1_035.txt, 1_036.txt, 1_037.txt, 1_038.txt, 1_039.txt, 1_040.txt, 1_041.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
206 ms
6524 KB
1_004.txt
AC
203 ms
6524 KB
1_005.txt
AC
207 ms
6524 KB
1_006.txt
AC
221 ms
6524 KB
1_007.txt
AC
204 ms
6652 KB
1_008.txt
AC
205 ms
6652 KB
1_009.txt
AC
205 ms
6652 KB
1_010.txt
AC
202 ms
6652 KB
1_011.txt
AC
207 ms
6652 KB
1_012.txt
AC
203 ms
6780 KB
1_013.txt
AC
206 ms
6780 KB
1_014.txt
AC
207 ms
6652 KB
1_015.txt
AC
205 ms
6780 KB
1_016.txt
AC
206 ms
6780 KB
1_017.txt
AC
206 ms
6780 KB
1_018.txt
AC
209 ms
6908 KB
1_019.txt
AC
207 ms
6908 KB
1_020.txt
AC
216 ms
6908 KB
1_021.txt
AC
205 ms
6908 KB
1_022.txt
AC
208 ms
7036 KB
1_023.txt
AC
209 ms
7036 KB
1_024.txt
AC
207 ms
6780 KB
1_025.txt
AC
207 ms
7164 KB
1_026.txt
AC
207 ms
7164 KB
1_027.txt
AC
207 ms
6908 KB
1_028.txt
AC
206 ms
6908 KB
1_029.txt
AC
213 ms
7164 KB
1_030.txt
AC
208 ms
6908 KB
1_031.txt
AC
206 ms
6908 KB
1_032.txt
AC
211 ms
7292 KB
1_033.txt
AC
195 ms
5116 KB
1_034.txt
AC
206 ms
5116 KB
1_035.txt
AC
213 ms
7164 KB
1_036.txt
AC
204 ms
5116 KB
1_037.txt
AC
201 ms
5244 KB
1_038.txt
AC
211 ms
7164 KB
1_039.txt
AC
201 ms
4988 KB
1_040.txt
AC
203 ms
5244 KB
1_041.txt
AC
214 ms
7292 KB