Submission #1591368
Source Code Expand
#include <cstdio>
#include <algorithm>
#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
using namespace std;
typedef long long LL;
const int N = 100010;
LL r[N], a[N], b[N], z[N];
int main()
{
LL x, k;
scanf("%lld%lld", &x, &k);
a[0] = 0, b[0] = x;
Rep(i, k) {
scanf("%lld", &r[i]);
LL tmp = r[i] - r[i - 1];
a[i] = a[i - 1], b[i] = b[i - 1], z[i] = z[i - 1];
if (i & 1) {
if (z[i] >= tmp) z[i] -= tmp;
else if (tmp <= b[i] - a[i] + z[i])
a[i] += tmp - a[i], z[i] = 0;
else z[i] = 0, a[i] = 0, b[i] = 0;
}
else {
if (z[i] + b[i] - a[i] + tmp <= x) z[i] += tmp;
else if (z[i] + tmp <= x)
z[i] += tmp, b[i] -= z[i] + b[i] - a[i] - x;
else z[i] = x, a[i] = 0, b[i] = 0;
}
//printf("%d %d %d\n", z[i], a[i], b[i]);
}
int q;
scanf("%d", &q);
Rep(i, q) {
LL a0, t0;
scanf("%lld%lld", &t0, &a0);
LL tmp = (upper_bound(r + 1, r + 1 + k, t0) - r) - 1;
LL ans;
if (a0 <= a[tmp]) ans = z[tmp];
else if (a0 <= b[tmp]) ans = z[tmp] + a0 - a[tmp];
else ans = z[tmp] + b[tmp] - a[tmp];
LL tx = t0 - r[tmp];
if ((tmp + 1) & 1) ans = max(0ll, ans - tx);
else ans = min(x, ans + tx);
printf("%lld\n", ans);
}
return 0;
}
/*
180
3
60 120 180
1
180 180
*/
Submission Info
Submission Time |
|
Task |
F - Sandglass |
User |
dujvet |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1393 Byte |
Status |
WA |
Exec Time |
52 ms |
Memory |
4224 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:17:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld", &x, &k);
^
./Main.cpp:20:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &r[i]);
^
./Main.cpp:38:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &q);
^
./Main.cpp:41:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld", &t0, &a0);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 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 |
0 ms |
128 KB |
0_001.txt |
AC |
0 ms |
128 KB |
0_002.txt |
AC |
0 ms |
128 KB |
1_003.txt |
AC |
40 ms |
3456 KB |
1_004.txt |
AC |
41 ms |
3456 KB |
1_005.txt |
AC |
43 ms |
3456 KB |
1_006.txt |
WA |
39 ms |
3456 KB |
1_007.txt |
AC |
41 ms |
3584 KB |
1_008.txt |
AC |
42 ms |
3584 KB |
1_009.txt |
WA |
39 ms |
3584 KB |
1_010.txt |
AC |
41 ms |
3584 KB |
1_011.txt |
AC |
52 ms |
3584 KB |
1_012.txt |
WA |
40 ms |
3712 KB |
1_013.txt |
WA |
41 ms |
3712 KB |
1_014.txt |
AC |
43 ms |
3584 KB |
1_015.txt |
WA |
40 ms |
3712 KB |
1_016.txt |
WA |
42 ms |
3712 KB |
1_017.txt |
AC |
45 ms |
3712 KB |
1_018.txt |
WA |
41 ms |
3840 KB |
1_019.txt |
WA |
43 ms |
3840 KB |
1_020.txt |
WA |
45 ms |
3840 KB |
1_021.txt |
WA |
41 ms |
3840 KB |
1_022.txt |
WA |
43 ms |
3968 KB |
1_023.txt |
WA |
46 ms |
3968 KB |
1_024.txt |
WA |
42 ms |
3712 KB |
1_025.txt |
WA |
44 ms |
4096 KB |
1_026.txt |
WA |
46 ms |
4096 KB |
1_027.txt |
WA |
43 ms |
3840 KB |
1_028.txt |
WA |
44 ms |
3840 KB |
1_029.txt |
WA |
47 ms |
4096 KB |
1_030.txt |
WA |
44 ms |
3840 KB |
1_031.txt |
WA |
45 ms |
3840 KB |
1_032.txt |
WA |
48 ms |
4224 KB |
1_033.txt |
AC |
31 ms |
1024 KB |
1_034.txt |
WA |
31 ms |
1024 KB |
1_035.txt |
WA |
45 ms |
4096 KB |
1_036.txt |
AC |
32 ms |
1024 KB |
1_037.txt |
WA |
33 ms |
1024 KB |
1_038.txt |
WA |
47 ms |
4096 KB |
1_039.txt |
AC |
32 ms |
768 KB |
1_040.txt |
WA |
34 ms |
1152 KB |
1_041.txt |
WA |
48 ms |
4224 KB |