Submission #1560983
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
struct jer {
int ahi, alo, curhi, curlo;
bool asc;
};
int r[100005];
jer changes[100005];
int main() {
int x, k;
scanf("%d %d", &x, &k);
jer lastchange = {x, 0, x, 0, false};
changes[0] = lastchange;
int last = 0;
for (int i = 1; i <= k + 1; i++) {
if (i == k + 1) {
r[i] = 1000000001;
} else {
scanf("%d", &r[i]);
}
int dt = r[i] - last;
last = r[i];
if (i % 2 == 1) {
changes[i].ahi = lastchange.ahi;
changes[i].curhi = max(0, lastchange.curhi - dt);
changes[i].curlo = max(0, lastchange.curlo - dt);
changes[i].alo = changes[i].ahi - (changes[i].curhi - changes[i].curlo);
changes[i].asc = true;
} else {
changes[i].alo = lastchange.alo;
changes[i].curhi = min(x, lastchange.curhi + dt);
changes[i].curlo = min(x, lastchange.curlo + dt);
changes[i].ahi = changes[i].alo + (changes[i].curhi - changes[i].curlo);
changes[i].asc = false;
}
lastchange = changes[i];
}
int q;
scanf("%d", &q);
for (int i = 0; i < q; i++) {
int t, a;
scanf("%d %d", &t, &a);
int offset = upper_bound(r, r + k + 2, t) - r - 1;
int p = 0;
if (a > changes[offset].ahi) {
p = changes[offset].curhi;
} else if (a < changes[offset].alo) {
p = changes[offset].curlo;
} else {
p = changes[offset].curlo + a - changes[offset].alo;
}
p += (changes[offset].asc ? 1 : -1) * (t - r[offset]);
p = min(x, p);
p = max(0, p);
printf("%d\n", p);
}
return 0;
}
Submission Info
Submission Time |
|
Task |
F - Sandglass |
User |
microtony |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
1628 Byte |
Status |
AC |
Exec Time |
51 ms |
Memory |
3584 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:11:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &x, &k);
^
./Main.cpp:19:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &r[i]);
^
./Main.cpp:39:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &q);
^
./Main.cpp:42:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &t, &a);
^
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 |
1 ms |
256 KB |
0_001.txt |
AC |
1 ms |
256 KB |
0_002.txt |
AC |
1 ms |
256 KB |
1_003.txt |
AC |
42 ms |
2816 KB |
1_004.txt |
AC |
44 ms |
2816 KB |
1_005.txt |
AC |
46 ms |
2816 KB |
1_006.txt |
AC |
42 ms |
2816 KB |
1_007.txt |
AC |
43 ms |
2816 KB |
1_008.txt |
AC |
45 ms |
2816 KB |
1_009.txt |
AC |
42 ms |
2816 KB |
1_010.txt |
AC |
43 ms |
2816 KB |
1_011.txt |
AC |
45 ms |
2944 KB |
1_012.txt |
AC |
43 ms |
2944 KB |
1_013.txt |
AC |
44 ms |
2944 KB |
1_014.txt |
AC |
46 ms |
2944 KB |
1_015.txt |
AC |
43 ms |
3072 KB |
1_016.txt |
AC |
44 ms |
3072 KB |
1_017.txt |
AC |
47 ms |
3072 KB |
1_018.txt |
AC |
44 ms |
3200 KB |
1_019.txt |
AC |
45 ms |
3200 KB |
1_020.txt |
AC |
47 ms |
3200 KB |
1_021.txt |
AC |
44 ms |
3072 KB |
1_022.txt |
AC |
47 ms |
3200 KB |
1_023.txt |
AC |
48 ms |
3200 KB |
1_024.txt |
AC |
45 ms |
3072 KB |
1_025.txt |
AC |
47 ms |
3328 KB |
1_026.txt |
AC |
49 ms |
3328 KB |
1_027.txt |
AC |
46 ms |
3072 KB |
1_028.txt |
AC |
47 ms |
3200 KB |
1_029.txt |
AC |
50 ms |
3456 KB |
1_030.txt |
AC |
47 ms |
3200 KB |
1_031.txt |
AC |
48 ms |
3200 KB |
1_032.txt |
AC |
50 ms |
3584 KB |
1_033.txt |
AC |
31 ms |
1024 KB |
1_034.txt |
AC |
33 ms |
1024 KB |
1_035.txt |
AC |
47 ms |
3328 KB |
1_036.txt |
AC |
33 ms |
1152 KB |
1_037.txt |
AC |
34 ms |
1152 KB |
1_038.txt |
AC |
49 ms |
3456 KB |
1_039.txt |
AC |
33 ms |
896 KB |
1_040.txt |
AC |
35 ms |
1280 KB |
1_041.txt |
AC |
51 ms |
3584 KB |