답안 #57760

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
57760 2018-07-16T02:48:01 Z spencercompton Sparklers (JOI17_sparklers) C++17
100 / 100
212 ms 31820 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, k;
ll t;
bool v[1001][1001];
ll pos[1001];
// ll dp[2][1000][1000];
// ll pos[1000];
vector<ll> all;
int main(){
	ll tt;
	cin >> n >> k >> tt;
	for(int i = 0; i<n; i++){
		cin >> pos[i];
	}
	k--;
	ll low = 0LL;
	ll high = 1000000000LL;
	while(low<high){
		ll mid = (low+high)/2LL;
		t = mid*tt;
		vector<ll> ar[2];
		for(int i = 0; i<2; i++){
			ar[i].push_back(0);
		}
		for(int i = k+1; i<n; i++){
			ar[0].push_back(ar[0][ar[0].size()-1] + 2LL * t - (pos[i]-pos[i-1]));
		}
		for(int i = k-1; i>=0; i--){
			ar[1].push_back(ar[1][ar[1].size()-1] + 2LL * t - (pos[i+1] - pos[i]));
		}
		// if(mid==9){
		// 	cout << "Q " << endl;
		// 	for(int i = 0; i<2; i++){
		// 		for(int j = 0; j<ar[i].size(); j++){
		// 			cout << ar[i][j] << " " ;
		// 		}
		// 		cout << endl;
		// 	}
		// }
		vector<pair<int, ll> > f[2];
		vector<pair<int, ll> > b[2];
		vector<ll> pre[2];
		for(int i = 0; i<2; i++){
			f[i].push_back(make_pair(0,0));
			int sz = 1;
			for(int j = 1; j<ar[i].size(); j++){
				if(ar[i][j] > ar[i][f[i][sz-1].first]){
					sz++;
					f[i].push_back(make_pair(j,ar[i][j]));
				}
			}
			for(int j = 0; j+1<sz; j++){
				for(int a = f[i][j].first; a<f[i][j+1].first; a++){
					f[i][j].second = min(f[i][j].second,ar[i][a]);
				}
			}
			sz = 1;
			b[i].push_back(make_pair(ar[i].size()-1,ar[i][ar[i].size()-1]));
			for(int j = ar[i].size()-2; j>=0; j--){
				if(ar[i][j] > ar[i][b[i][sz-1].first]){
					sz++;
					b[i].push_back(make_pair(j,ar[i][j]));
				}
			}
			for(int j = sz-1; j>0; j--){
				for(int a = b[i][j].first; a<b[i][j-1].first; a++){
					b[i][j].second = min(b[i][j].second,ar[i][a]);
				}
			}
			pre[i].resize(sz);
			pre[i][0] = b[i][0].second;
			for(int j = 1; j<sz; j++){
				pre[i][j] = min(b[i][j].second,pre[i][j-1]);
			}
		}
		bool ok = true;
		int p1 = 0;
		int p2 = 0;
		while(p1+1<f[0].size() || p2+1<f[1].size()){
			if(p1+1<f[0].size() && ar[1][f[1][p2].first] + f[0][p1].second >=0LL){
				p1++;
			}
			else if(p2+1<f[1].size() && ar[0][f[0][p1].first] + f[1][p2].second >= 0LL){
				p2++;
			}
			else{
				ok = false;
				break;
			}
		}
		if(!ok){
			low = mid+1LL;
			continue;
		}
		p1 = b[0].size()-1;
		p2 = b[1].size()-1;
		// if(mid==9){
		// 	for(int i = 0; i<2; i++){
		// 		for(int j = 0; j<b[i].size(); j++){
		// 			cout  << b[i][j].first <<"," << b[i][j].second << " ";
		// 		}
		// 		cout << endl;
		// 	}
		// 	for(int i = 0; i<2; i++){
		// 		for(int j = 0; j<pre[i].size(); j++){
		// 			cout << pre[i][j] << " ";
		// 		}
		// 		cout << endl;
		// 	}
		// }
		while(p1>0 || p2>0){
			if(p1>0 && ar[1][b[1][p2].first] + b[0][p1].second >= 0LL && ar[0][b[0][p1-1].first] + pre[1][p2] >=0LL){
				p1--;
			}
			else if(p2>0 && ar[0][b[0][p1].first] + b[1][p2].second >= 0LL && ar[1][b[1][p2-1].first] + pre[0][p1] >=0LL){
				p2--;
			}
			else {
				ok = false;
				break;
			}
		}
		if(!ok){
			low = mid+1LL;
		}
		else{
			high = mid;
		}
	}
	cout << low << endl;
}

Compilation message

sparklers.cpp: In function 'int main()':
sparklers.cpp:48:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j = 1; j<ar[i].size(); j++){
                   ~^~~~~~~~~~~~~
sparklers.cpp:81:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(p1+1<f[0].size() || p2+1<f[1].size()){
         ~~~~^~~~~~~~~~~~
sparklers.cpp:81:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(p1+1<f[0].size() || p2+1<f[1].size()){
                             ~~~~^~~~~~~~~~~~
sparklers.cpp:82:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(p1+1<f[0].size() && ar[1][f[1][p2].first] + f[0][p1].second >=0LL){
       ~~~~^~~~~~~~~~~~
sparklers.cpp:85:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    else if(p2+1<f[1].size() && ar[0][f[0][p1].first] + f[1][p2].second >= 0LL){
            ~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 3 ms 448 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 508 KB Output is correct
8 Correct 3 ms 508 KB Output is correct
9 Correct 2 ms 532 KB Output is correct
10 Correct 3 ms 544 KB Output is correct
11 Correct 2 ms 544 KB Output is correct
12 Correct 3 ms 544 KB Output is correct
13 Correct 3 ms 544 KB Output is correct
14 Correct 4 ms 600 KB Output is correct
15 Correct 3 ms 600 KB Output is correct
16 Correct 4 ms 632 KB Output is correct
17 Correct 3 ms 632 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 3 ms 644 KB Output is correct
20 Correct 3 ms 644 KB Output is correct
21 Correct 2 ms 652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 3 ms 448 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 508 KB Output is correct
8 Correct 3 ms 508 KB Output is correct
9 Correct 2 ms 532 KB Output is correct
10 Correct 3 ms 544 KB Output is correct
11 Correct 2 ms 544 KB Output is correct
12 Correct 3 ms 544 KB Output is correct
13 Correct 3 ms 544 KB Output is correct
14 Correct 4 ms 600 KB Output is correct
15 Correct 3 ms 600 KB Output is correct
16 Correct 4 ms 632 KB Output is correct
17 Correct 3 ms 632 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 3 ms 644 KB Output is correct
20 Correct 3 ms 644 KB Output is correct
21 Correct 2 ms 652 KB Output is correct
22 Correct 5 ms 656 KB Output is correct
23 Correct 3 ms 668 KB Output is correct
24 Correct 4 ms 672 KB Output is correct
25 Correct 4 ms 680 KB Output is correct
26 Correct 4 ms 692 KB Output is correct
27 Correct 5 ms 704 KB Output is correct
28 Correct 4 ms 716 KB Output is correct
29 Correct 4 ms 728 KB Output is correct
30 Correct 5 ms 740 KB Output is correct
31 Correct 5 ms 752 KB Output is correct
32 Correct 5 ms 752 KB Output is correct
33 Correct 5 ms 776 KB Output is correct
34 Correct 4 ms 788 KB Output is correct
35 Correct 4 ms 800 KB Output is correct
36 Correct 5 ms 816 KB Output is correct
37 Correct 3 ms 824 KB Output is correct
38 Correct 5 ms 908 KB Output is correct
39 Correct 5 ms 920 KB Output is correct
40 Correct 5 ms 920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 3 ms 448 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 508 KB Output is correct
8 Correct 3 ms 508 KB Output is correct
9 Correct 2 ms 532 KB Output is correct
10 Correct 3 ms 544 KB Output is correct
11 Correct 2 ms 544 KB Output is correct
12 Correct 3 ms 544 KB Output is correct
13 Correct 3 ms 544 KB Output is correct
14 Correct 4 ms 600 KB Output is correct
15 Correct 3 ms 600 KB Output is correct
16 Correct 4 ms 632 KB Output is correct
17 Correct 3 ms 632 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 3 ms 644 KB Output is correct
20 Correct 3 ms 644 KB Output is correct
21 Correct 2 ms 652 KB Output is correct
22 Correct 5 ms 656 KB Output is correct
23 Correct 3 ms 668 KB Output is correct
24 Correct 4 ms 672 KB Output is correct
25 Correct 4 ms 680 KB Output is correct
26 Correct 4 ms 692 KB Output is correct
27 Correct 5 ms 704 KB Output is correct
28 Correct 4 ms 716 KB Output is correct
29 Correct 4 ms 728 KB Output is correct
30 Correct 5 ms 740 KB Output is correct
31 Correct 5 ms 752 KB Output is correct
32 Correct 5 ms 752 KB Output is correct
33 Correct 5 ms 776 KB Output is correct
34 Correct 4 ms 788 KB Output is correct
35 Correct 4 ms 800 KB Output is correct
36 Correct 5 ms 816 KB Output is correct
37 Correct 3 ms 824 KB Output is correct
38 Correct 5 ms 908 KB Output is correct
39 Correct 5 ms 920 KB Output is correct
40 Correct 5 ms 920 KB Output is correct
41 Correct 151 ms 4784 KB Output is correct
42 Correct 7 ms 4784 KB Output is correct
43 Correct 40 ms 4784 KB Output is correct
44 Correct 194 ms 8324 KB Output is correct
45 Correct 185 ms 8556 KB Output is correct
46 Correct 166 ms 9872 KB Output is correct
47 Correct 194 ms 10696 KB Output is correct
48 Correct 160 ms 11492 KB Output is correct
49 Correct 195 ms 13472 KB Output is correct
50 Correct 172 ms 13472 KB Output is correct
51 Correct 178 ms 14780 KB Output is correct
52 Correct 212 ms 16304 KB Output is correct
53 Correct 189 ms 17144 KB Output is correct
54 Correct 196 ms 18164 KB Output is correct
55 Correct 143 ms 18164 KB Output is correct
56 Correct 181 ms 19720 KB Output is correct
57 Correct 180 ms 21032 KB Output is correct
58 Correct 176 ms 21172 KB Output is correct
59 Correct 142 ms 21276 KB Output is correct
60 Correct 179 ms 23432 KB Output is correct
61 Correct 178 ms 24004 KB Output is correct
62 Correct 161 ms 24740 KB Output is correct
63 Correct 157 ms 25812 KB Output is correct
64 Correct 167 ms 26056 KB Output is correct
65 Correct 169 ms 26988 KB Output is correct
66 Correct 172 ms 27920 KB Output is correct
67 Correct 160 ms 28912 KB Output is correct
68 Correct 197 ms 30828 KB Output is correct
69 Correct 196 ms 31820 KB Output is correct