AtCoder Regular Contest 082

Submission #1591382

Source codeソースコード

#include<iostream>
#include<iomanip>
#include<vector>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<unordered_set>
using namespace std;
const int MAX = 100002;
const int INF = 1000000000;

int main() {
	int X, K, Q;
	int m[MAX], ub[MAX], lb[MAX], up[MAX], lo[MAX];
	vector<int> r;
	
	cin >> X >> K;
	r.push_back(0);
	for (int i = 1; i <= K; i++) {
		int temp;
		cin >> temp;
		r.push_back(temp);
	}
	r.push_back(INF);

	m[0] = 0;
	ub[0] = X;
	lb[0] = 0;
	up[0] = 0;
	lo[0] = 0;

	bool b = true;
	for (int i = 1; i < r.size(); i++) {
		int td = r[i] - r[i - 1];

		if (b) {
			ub[i] = max(0, ub[i - 1] - td);
			lb[i] = max(0, lb[i - 1] - td);
			m[i] = m[i - 1] - td;
		}
		else {
			ub[i] = min(X, ub[i - 1] + td);
			lb[i] = min(X, lb[i - 1] + td);
			m[i] = m[i - 1] + td;
		}

		up[i] = max(m[i], up[i - 1]);
		lo[i] = min(m[i], lo[i - 1]);

		b = !b;
	}

	cin >> Q;

	for (int i = 0; i < Q; i++) {
		int t, a;
		cin >> t >> a;

		vector<int>::iterator it = upper_bound(r.begin(), r.end(), t);

		int index = distance(r.begin(), it) - 1;

		int ans = 0;

		if (a + up[index] > X) {
			ans = ub[index];
		}
		else if (a + lo[index] < 0) {
			ans = lb[index];
		}
		else {
			ans = m[index] + a;
		}

		t -= r[index];
		if (index & 1) {
			ans = min(X, ans + t);
		}
		else {
			ans = max(0, ans - t);
		}

		cout << ans << endl;
	}
	return 0;
}

Submission

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

Test case

Set

Set name Score得点 / Max score Cases
Sample - 0_000.txt,0_001.txt,0_002.txt
All 700 / 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 1 ms 256 KB
0_001.txt AC 1 ms 256 KB
0_002.txt AC 1 ms 256 KB
1_003.txt AC 245 ms 2936 KB
1_004.txt AC 257 ms 2936 KB
1_005.txt AC 268 ms 2936 KB
1_006.txt AC 245 ms 2936 KB
1_007.txt AC 251 ms 2936 KB
1_008.txt AC 262 ms 2936 KB
1_009.txt AC 247 ms 2936 KB
1_010.txt AC 260 ms 2936 KB
1_011.txt AC 269 ms 3064 KB
1_012.txt AC 251 ms 3064 KB
1_013.txt AC 256 ms 3064 KB
1_014.txt AC 271 ms 3064 KB
1_015.txt AC 257 ms 3192 KB
1_016.txt AC 265 ms 3192 KB
1_017.txt AC 270 ms 3192 KB
1_018.txt AC 256 ms 3320 KB
1_019.txt AC 277 ms 3320 KB
1_020.txt AC 274 ms 3320 KB
1_021.txt AC 268 ms 3192 KB
1_022.txt AC 268 ms 3448 KB
1_023.txt AC 278 ms 3320 KB
1_024.txt AC 269 ms 3192 KB
1_025.txt AC 270 ms 3448 KB
1_026.txt AC 286 ms 3448 KB
1_027.txt AC 275 ms 3192 KB
1_028.txt AC 274 ms 3320 KB
1_029.txt AC 287 ms 3576 KB
1_030.txt AC 280 ms 3320 KB
1_031.txt AC 283 ms 3320 KB
1_032.txt AC 288 ms 3704 KB
1_033.txt AC 233 ms 1152 KB
1_034.txt AC 238 ms 1024 KB
1_035.txt AC 275 ms 3448 KB
1_036.txt AC 241 ms 1152 KB
1_037.txt AC 240 ms 1152 KB
1_038.txt AC 298 ms 3576 KB
1_039.txt AC 245 ms 896 KB
1_040.txt AC 245 ms 1280 KB
1_041.txt AC 295 ms 3704 KB