답안 #135868

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
135868 2019-07-24T12:46:07 Z imyujin MP3 Player (CEOI10_mp3player) C++14
100 / 100
138 ms 7168 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 100005;

struct NOD {
	int M, m, delta;

	NOD(int Vm = 0, int d = 0) {
		M = Vm - max(0, d);
		m = max(0, -d);
		delta = d;
	}

	NOD(int a, int b, int d) {
		M = a;
		m = b;
		delta = d;
	}

	void print() {
		printf("M = %d, m = %d, delta = %d\n", M, m, delta);
	}
} seg[4 * MAXN];

char B[MAXN];
int T[MAXN], ts[MAXN];
int Vm;

void updseg(int idx, int l, int r, int x, int z) {
	if(l == r) seg[idx] = NOD(Vm, z);
	else {
		int m = (l + r) / 2;
		if(x <= m) updseg(idx * 2, l, m, x, z);
		else updseg(idx * 2 + 1, m + 1, r, x, z);
		NOD &L = seg[idx * 2], &R = seg[idx * 2 + 1];
		if(L.M + L.delta <= R.m) 
			seg[idx] = NOD(Vm, Vm, R.m + R.delta - Vm);
		else if(L.m + L.delta >= R.M) 
			seg[idx] = NOD(Vm, Vm, R.M + R.delta - Vm);
		else 
			seg[idx] = NOD(min(L.M, R.M - L.delta), max(L.m, R.m - L.delta), L.delta + R.delta);
	}
}

int main() {
	int N, V2;
	int Tans, Vans;

	cin >> N >> Vm >> V2;
	for(int i = 0; i < N; i++) cin >> B[i] >> T[i];

	for(int i = N - 1; i > 0; i--) T[i] -= T[i - 1];
	for(int i = 1; i < 4 * N; i++) seg[i] = NOD(Vm);

	for(int i = 0; i < N - 1; i++) ts[i] = i + 1;
	sort(ts, ts + N - 1, [&](const int a, const int b) { return T[a] < T[b]; } );
	//for(int i = 0; i < N - 1; i++) printf("%d ", ts[i]);
	//printf("\n");

	Tans = T[ts[0]] - 1;
	Vans = V2;
	ts[N - 1] = N;
	T[N] = 0;
	for(int i = 0; i < N - 1; i++) {
		updseg(1, 0, N - 1, ts[i], B[ts[i]] == '+' ? 1 : -1);
		if(T[ts[i]] != T[ts[i + 1]]) {
			if(seg[1].M + seg[1].delta == V2) {
				Tans = T[ts[i + 1]] - 1;
				Vans = Vm;
			}
			else if(seg[1].m < V2 - seg[1].delta && V2 - seg[1].delta < seg[1].M) {
				Tans = T[ts[i + 1]] - 1;
				Vans = V2 - seg[1].delta;
			}
			else if(seg[1].m + seg[1].delta == V2) {
				Tans = T[ts[i + 1]] - 1;
				Vans = seg[1].m;
			}
		}
		//seg[1].print();
	}

	if(Tans == -1) cout << "infinity";
	else cout << Tans << " " << Vans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 4984 KB Output is correct
2 Correct 9 ms 4984 KB Output is correct
3 Correct 9 ms 5112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5112 KB Output is correct
2 Correct 7 ms 5116 KB Output is correct
3 Correct 7 ms 4984 KB Output is correct
4 Correct 9 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 5112 KB Output is correct
2 Correct 10 ms 5112 KB Output is correct
3 Correct 10 ms 5112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 5240 KB Output is correct
2 Correct 31 ms 5240 KB Output is correct
3 Correct 31 ms 5240 KB Output is correct
4 Correct 27 ms 5240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 5240 KB Output is correct
2 Correct 36 ms 5240 KB Output is correct
3 Correct 35 ms 5368 KB Output is correct
4 Correct 30 ms 5240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 5232 KB Output is correct
2 Correct 42 ms 5368 KB Output is correct
3 Correct 48 ms 5368 KB Output is correct
4 Correct 37 ms 5192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 5456 KB Output is correct
2 Correct 64 ms 5416 KB Output is correct
3 Correct 51 ms 5316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 132 ms 5880 KB Output is correct
2 Correct 129 ms 7168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 138 ms 5928 KB Output is correct
2 Correct 128 ms 7112 KB Output is correct