답안 #55380

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
55380 2018-07-07T05:55:14 Z ksun48 Sparklers (JOI17_sparklers) C++14
100 / 100
231 ms 33620 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

LL ok(vector<LL> a, vector<LL> b){
	LL dp[a.size()][b.size()];
	for(int i = 0; i < a.size(); i++){
		for(int j = 0; j < b.size(); j++){
			dp[i][j] = 0;
			if(a[i] >= b[j]){
				if((i == 0 && j == 0) || (i > 0 && dp[i-1][j]) || (j > 0 && dp[i][j-1])){
					dp[i][j] = 1;
				}
			}
		}
	}
	return dp[a.size()-1][b.size()-1];
}

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

LL okay(vector<LL> a, vector<LL> b){
	LL ma = 0;
	LL mb = 0;
	for(LL j = 0; j < a.size(); j++){
		if(a[j] >= a[ma]) ma = j;
	}
	for(LL j = 0; j < b.size(); j++){
		if(b[j] <= b[mb]) mb = j;
	}
	vector<LL> la, lb;
	vector<LL> ra, rb;
	for(LL j = 0; j <= ma; j++) la.push_back(a[j]);
	for(LL j = a.size()-1; j >= ma; j--) ra.push_back(a[j]);
	for(LL j = 0; j <= mb; j++) lb.push_back(b[j]);
	for(LL 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(LL 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 'LL ok(std::vector<long long int>, std::vector<long long int>)':
sparklers.cpp:7:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < a.size(); i++){
                 ~~^~~~~~~~~~
sparklers.cpp:8:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0; j < b.size(); j++){
                  ~~^~~~~~~~~~
sparklers.cpp: In function 'LL reach(std::vector<long long int>, std::vector<long long int>)':
sparklers.cpp:25:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(LL i = 0; i < a.size(); i++){
                ~~^~~~~~~~~~
sparklers.cpp:35:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(LL i = 0; i < b.size(); i++){
                ~~^~~~~~~~~~
sparklers.cpp:45:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(i + 1 < acompress.size() || j + 1 < bcompress.size()){
        ~~~~~~^~~~~~~~~~~~~~~~~~
sparklers.cpp:45:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(i + 1 < acompress.size() || j + 1 < bcompress.size()){
                                    ~~~~~~^~~~~~~~~~~~~~~~~~
sparklers.cpp:46:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(j + 1 < bcompress.size() && bcompress[j+1].second <= acompress[i].first){
      ~~~~~~^~~~~~~~~~~~~~~~~~
sparklers.cpp:48:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   } else if(i + 1 < acompress.size() && bcompress[j].first <= acompress[i+1].second){
             ~~~~~~^~~~~~~~~~~~~~~~~~
sparklers.cpp: In function 'LL okay(std::vector<long long int>, std::vector<long long int>)':
sparklers.cpp:60:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(LL j = 0; j < a.size(); j++){
                ~~^~~~~~~~~~
sparklers.cpp:63:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(LL j = 0; j < b.size(); j++){
                ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 3 ms 492 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 2 ms 672 KB Output is correct
11 Correct 3 ms 672 KB Output is correct
12 Correct 3 ms 672 KB Output is correct
13 Correct 2 ms 672 KB Output is correct
14 Correct 2 ms 672 KB Output is correct
15 Correct 3 ms 672 KB Output is correct
16 Correct 3 ms 672 KB Output is correct
17 Correct 2 ms 672 KB Output is correct
18 Correct 2 ms 736 KB Output is correct
19 Correct 2 ms 736 KB Output is correct
20 Correct 2 ms 736 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 3 ms 492 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 2 ms 672 KB Output is correct
11 Correct 3 ms 672 KB Output is correct
12 Correct 3 ms 672 KB Output is correct
13 Correct 2 ms 672 KB Output is correct
14 Correct 2 ms 672 KB Output is correct
15 Correct 3 ms 672 KB Output is correct
16 Correct 3 ms 672 KB Output is correct
17 Correct 2 ms 672 KB Output is correct
18 Correct 2 ms 736 KB Output is correct
19 Correct 2 ms 736 KB Output is correct
20 Correct 2 ms 736 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
22 Correct 3 ms 736 KB Output is correct
23 Correct 3 ms 736 KB Output is correct
24 Correct 3 ms 736 KB Output is correct
25 Correct 3 ms 736 KB Output is correct
26 Correct 3 ms 736 KB Output is correct
27 Correct 3 ms 736 KB Output is correct
28 Correct 3 ms 736 KB Output is correct
29 Correct 3 ms 736 KB Output is correct
30 Correct 3 ms 736 KB Output is correct
31 Correct 4 ms 736 KB Output is correct
32 Correct 3 ms 736 KB Output is correct
33 Correct 3 ms 736 KB Output is correct
34 Correct 3 ms 736 KB Output is correct
35 Correct 3 ms 736 KB Output is correct
36 Correct 3 ms 736 KB Output is correct
37 Correct 3 ms 736 KB Output is correct
38 Correct 3 ms 736 KB Output is correct
39 Correct 3 ms 736 KB Output is correct
40 Correct 3 ms 736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 3 ms 492 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 2 ms 672 KB Output is correct
11 Correct 3 ms 672 KB Output is correct
12 Correct 3 ms 672 KB Output is correct
13 Correct 2 ms 672 KB Output is correct
14 Correct 2 ms 672 KB Output is correct
15 Correct 3 ms 672 KB Output is correct
16 Correct 3 ms 672 KB Output is correct
17 Correct 2 ms 672 KB Output is correct
18 Correct 2 ms 736 KB Output is correct
19 Correct 2 ms 736 KB Output is correct
20 Correct 2 ms 736 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
22 Correct 3 ms 736 KB Output is correct
23 Correct 3 ms 736 KB Output is correct
24 Correct 3 ms 736 KB Output is correct
25 Correct 3 ms 736 KB Output is correct
26 Correct 3 ms 736 KB Output is correct
27 Correct 3 ms 736 KB Output is correct
28 Correct 3 ms 736 KB Output is correct
29 Correct 3 ms 736 KB Output is correct
30 Correct 3 ms 736 KB Output is correct
31 Correct 4 ms 736 KB Output is correct
32 Correct 3 ms 736 KB Output is correct
33 Correct 3 ms 736 KB Output is correct
34 Correct 3 ms 736 KB Output is correct
35 Correct 3 ms 736 KB Output is correct
36 Correct 3 ms 736 KB Output is correct
37 Correct 3 ms 736 KB Output is correct
38 Correct 3 ms 736 KB Output is correct
39 Correct 3 ms 736 KB Output is correct
40 Correct 3 ms 736 KB Output is correct
41 Correct 111 ms 5516 KB Output is correct
42 Correct 8 ms 5516 KB Output is correct
43 Correct 32 ms 5516 KB Output is correct
44 Correct 200 ms 10444 KB Output is correct
45 Correct 213 ms 10444 KB Output is correct
46 Correct 163 ms 12588 KB Output is correct
47 Correct 196 ms 13660 KB Output is correct
48 Correct 173 ms 13660 KB Output is correct
49 Correct 145 ms 15232 KB Output is correct
50 Correct 185 ms 15232 KB Output is correct
51 Correct 179 ms 17472 KB Output is correct
52 Correct 211 ms 18168 KB Output is correct
53 Correct 190 ms 19172 KB Output is correct
54 Correct 212 ms 19856 KB Output is correct
55 Correct 201 ms 20040 KB Output is correct
56 Correct 181 ms 22324 KB Output is correct
57 Correct 210 ms 23192 KB Output is correct
58 Correct 231 ms 23192 KB Output is correct
59 Correct 202 ms 23192 KB Output is correct
60 Correct 213 ms 25208 KB Output is correct
61 Correct 222 ms 25672 KB Output is correct
62 Correct 197 ms 27248 KB Output is correct
63 Correct 182 ms 27572 KB Output is correct
64 Correct 155 ms 27832 KB Output is correct
65 Correct 155 ms 28724 KB Output is correct
66 Correct 178 ms 29724 KB Output is correct
67 Correct 156 ms 30596 KB Output is correct
68 Correct 172 ms 32508 KB Output is correct
69 Correct 171 ms 33620 KB Output is correct