Submission #55336

# Submission time Handle Problem Language Result Execution time Memory
55336 2018-07-07T04:49:53 Z ksun48 Sparklers (JOI17_sparklers) C++14
0 / 100
2 ms 432 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int reach(vector<LL> a, vector<LL> b){
	vector<pair<LL,LL> > acompress, bcompress;
	LL acur = 0;
	LL curmin = a[0];
	for(int i = 0; i < a.size(); i++){
		if(a[i] >= acur){
			acompress.push_back({acur, curmin});
			acur = a[i];
			curmin = a[i];
		}
		curmin = min(curmin, a[i]);
	}
	LL bcur = 0;
	LL curmax = b[0];
	for(int i = 0; i < b.size(); i++){
		if(b[i] <= bcur){
			bcompress.push_back({bcur, curmax});
			bcur = b[i];
			curmax = b[i];
		}
		curmax = max(curmax, b[i]);
	}
	LL i = 0;
	LL j = 0;
	while(i < acompress.size() - 1 && j < bcompress.size() - 1){
		if(bcompress[j+1].second <= acompress[i].first){
			j++;
		} else if(bcompress[j].first <= acompress[i+1].second){
			i++;
		} else {
			return 0;
		}
	}
	return 1;
}

int okay(vector<LL> a, vector<LL> b){
	if(a[0] < b[0] || a[a.size()-1] < b[b.size() - 1]) return 0;
	int ma = 0;
	int mb = 0;
	for(int j = 0; j < a.size(); j++){
		if(a[j] > a[ma]) ma = j;
	}
	for(int j = 0; j < b.size(); j++){
		if(b[j] < b[mb]) mb = j;
	}
	vector<LL> la, lb;
	vector<LL> ra, rb;
	for(int j = 0; j <= ma; j++) la.push_back(a[j]);
	for(int j = a.size()-1; j >= ma; j--) ra.push_back(a[j]);
	for(int j = 0; j <= mb; j++) lb.push_back(b[j]);
	for(int j = b.size()-1; j >= mb; j--) rb.push_back(b[j]);
	return reach(la, lb) && reach(ra, rb);
}

int main(){
	cin.sync_with_stdio(0); cin.tie(0);
	LL n, k, t;
	cin >> n >> k >> t;
	k--;
	vector<LL> x(n);
	for(int i = 0; i < n; i++){
		cin >> x[i];
	}		
	LL s = -1;
	LL e = 1000000000;
	while(s + 1 < e){
		LL m = (s + e) / 2;
		vector<LL> y = x;
		for(LL i = 0; i < n; i++){
			y[i] -= m * t * 2 * i;
		}
		vector<LL> a, b;
		for(LL i = k; i >= 0; i--){
			a.push_back(y[i]);
		}
		for(LL i = k; i < n; i++){
			b.push_back(y[i]);
		}
		if(okay(a,b)){
			e = m;
		} else {
			s = m;
		}
	}
	cout << e << '\n';
}

Compilation message

sparklers.cpp: In function 'int reach(std::vector<long long int>, std::vector<long long int>)':
sparklers.cpp:9:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < a.size(); i++){
                 ~~^~~~~~~~~~
sparklers.cpp:19:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < b.size(); i++){
                 ~~^~~~~~~~~~
sparklers.cpp:29:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(i < acompress.size() - 1 && j < bcompress.size() - 1){
        ~~^~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:29:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(i < acompress.size() - 1 && j < bcompress.size() - 1){
                                    ~~^~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp: In function 'int okay(std::vector<long long int>, std::vector<long long int>)':
sparklers.cpp:45:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 0; j < a.size(); j++){
                 ~~^~~~~~~~~~
sparklers.cpp:48:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 0; j < b.size(); j++){
                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Incorrect 2 ms 432 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Incorrect 2 ms 432 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Incorrect 2 ms 432 KB Output isn't correct
4 Halted 0 ms 0 KB -