Submission #135490

# Submission time Handle Problem Language Result Execution time Memory
135490 2019-07-24T06:46:22 Z 이온조(#3249) MP3 Player (CEOI10_mp3player) C++14
0 / 100
1000 ms 3048 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define X first
#define Y second

struct seg {
	vector<int> mn, mx, L;
	void init(int idx, int s, int e, int v) {
		if(s == e) {
			mn[idx] = mx[idx] = v;
			return;
		}
		int m = s+e >> 1;
		init(idx*2, s, m, v);
		init(idx*2+1, m+1, e, v);
		mn[idx] = mx[idx] = v;
	}
	void upl(int idx, int s, int e) {
		if(L[idx]) {
			mn[idx] += L[idx];
			mx[idx] += L[idx];
			if(s != e) {
				L[idx*2] += L[idx];
				L[idx*2+1] += L[idx];
			}
			L[idx] = 0;
		}
	}
	void upd(int idx, int s, int e, int l, int r, int v) {
		upl(idx, s, e);
		if(r < s || e < l) return;
		if(l <= s && e <= r) {
			L[idx] += v;
			upl(idx, s, e);
			return;
		}
		int m = s+e >> 1;
		upd(idx*2, s, m, l, r, v);
		upd(idx*2+1, m+1, e, l, r, v);
		mn[idx] = min(mn[idx*2], mn[idx*2+1]);
		mx[idx] = max(mx[idx*2], mx[idx*2+1]);
	}
	pii get(int idx, int s, int e) {
		upl(idx, s, e);
		return {mn[idx], mx[idx]};
	}
	seg(int N, int V2) {
		mn.resize(4*N);
		mx.resize(4*N);
		L.resize(4*N);
		init(1, 1, N, V2);
	}
};

int C[100009];
char T[100009];
vector<pii> S;
bool chk[100009];

int main() {
	int N, VM, V2; scanf("%d%d%d",&N,&VM,&V2);
	int ans = 0, V1 = V2;
	for(int i=1; i<=N; i++) {
		scanf(" %c%d", &T[i], &C[i]);
		if(i >= 2) S.push_back({C[i] - C[i-1], i});
	}
	sort(S.begin(), S.end());
	for(int k=0; k<N-1; k++) {
		pii it = S[k];
		chk[it.Y] = 1;
		bool f = 1;
		int L = V2, R = V2;
		for(int i=N; i>=1; i--) {
			if(!chk[i]) continue;
			if(T[i] == '+') {
				if(R == VM) --L;
				else --L, --R;
				L = max(L, 0);
			}
			if(T[i] == '-') {
				if(L == 0) ++R;
				else ++L, ++R;
				R = min(R, VM);
			}
			if(R < L) f = 0;
		}
		if(f) {
			if(k+2 == N) return !printf("infinity");
			ans = S[k+1].X - 1; V1 = R;
		}
	}
	printf("%d %d\n", ans, V1);
	return 0;
}

Compilation message

mp3player.cpp: In member function 'void seg::init(int, int, int, int)':
mp3player.cpp:14:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = s+e >> 1;
           ~^~
mp3player.cpp: In member function 'void seg::upd(int, int, int, int, int, int)':
mp3player.cpp:38:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = s+e >> 1;
           ~^~
mp3player.cpp: In function 'int main()':
mp3player.cpp:62:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int N, VM, V2; scanf("%d%d%d",&N,&VM,&V2);
                 ~~~~~^~~~~~~~~~~~~~~~~~~~~
mp3player.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c%d", &T[i], &C[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 504 KB Output is correct
2 Incorrect 23 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 376 KB Output is correct
2 Correct 7 ms 376 KB Output is correct
3 Incorrect 7 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1054 ms 1064 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1064 ms 1144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1047 ms 1144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 1780 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 2924 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 3048 KB Time limit exceeded
2 Halted 0 ms 0 KB -