AtCoder Regular Contest 082

Submission #1591368

Source codeソースコード

#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

Task問題 F - Sandglass
User nameユーザ名 dujvet
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 1393 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Compiler messageコンパイルメッセージ

./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);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - 0_000.txt,0_001.txt,0_002.txt
All 0 / 700 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
0_000.txt AC
0_001.txt AC
0_002.txt AC
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
1_007.txt AC 41 ms 3584 KB
1_008.txt AC 42 ms 3584 KB
1_009.txt WA
1_010.txt AC 41 ms 3584 KB
1_011.txt AC 52 ms 3584 KB
1_012.txt WA
1_013.txt WA
1_014.txt AC 43 ms 3584 KB
1_015.txt WA
1_016.txt WA
1_017.txt AC 45 ms 3712 KB
1_018.txt WA
1_019.txt WA
1_020.txt WA
1_021.txt WA
1_022.txt WA
1_023.txt WA
1_024.txt WA
1_025.txt WA
1_026.txt WA
1_027.txt WA
1_028.txt WA
1_029.txt WA
1_030.txt WA
1_031.txt WA
1_032.txt WA
1_033.txt AC 31 ms 1024 KB
1_034.txt WA
1_035.txt WA
1_036.txt AC 32 ms 1024 KB
1_037.txt WA
1_038.txt WA
1_039.txt AC 32 ms 768 KB
1_040.txt WA
1_041.txt WA