답안 #836949

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
836949 2023-08-24T17:55:21 Z Abrar_Al_Samit 송신탑 (IOI22_towers) C++17
23 / 100
4000 ms 7504 KB
#include "towers.h"
#include <bits/stdc++.h>

using namespace std;

//subtask 2 & 3

const int nax = 100005;
int n;
bool l_maxima[nax];
int l[nax], r[nax];
int h[nax];
int pmax[nax], nmax[nax];

void init(int N, vector<int> H) {
  n = N;

  for(int i=0; i<n; ++i) h[i] = H[i]; 
}

bool is[nax];
int max_towers(int L, int R, int D) {
	vector<int>H;
	for(int i=L; i<=R; ++i) {
		H.push_back(h[i]);
	}
	n = R-L+1;

	int mn = H[0];
  	for(int i=1; i<n-1; ++i) {
    	if(H[i]>H[i-1] && H[i]>H[i+1]) {
    		l_maxima[i] = 1;
    		l[i] = H[i] - mn;
    		mn = 2e9;
    	} else {
    		mn = min(mn, H[i]);
    	}
  	}


  	int p = -1;
  	for(int i=1; i<n; ++i) if(l_maxima[i]) {
  		pmax[i] = p;
  		p = i;
  	}
  	p = n;
  	for(int i=n-1; i>0; --i) if(l_maxima[i]) {
  		nmax[i] = p;
  		p = i;
  	}

  	mn = H[n-1];
  	for(int i=n-2; i>0; --i) {
  		if(l_maxima[i]) {
  			r[i] = H[i] - mn;
  			mn = 2e9;
  		} else {
  			mn = min(mn, H[i]);
  		}
  	}



	int ret = 1;

	set<pair<int,int>>s;
	for(int i=1; i<n; ++i) if(l_maxima[i]) {
		s.insert({H[i], i});
		is[i] = 1;
	}

	while(!s.empty()) {
		auto [x, i] = *s.begin();
		s.erase(s.begin());
		is[i] = 0;

		if(min(l[i], r[i])>=D) {
			++ret;
			continue;
		}

		int lmin = H[i] - l[i], rmin = H[i] - r[i];

		if(pmax[i]!=-1 && is[pmax[i]]) {
			r[pmax[i]] = max(r[pmax[i]], H[pmax[i]] - rmin);
			nmax[pmax[i]] = nmax[i];
		}
		if(nmax[i]!=n && is[nmax[i]]) {
			l[nmax[i]] = max(l[nmax[i]], H[nmax[i]] - lmin);
			pmax[nmax[i]] = pmax[i];
		}
	} 
	return ret;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4046 ms 2248 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 0 ms 336 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 0 ms 208 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 0 ms 208 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 0 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 0 ms 336 KB Output is correct
33 Correct 0 ms 208 KB Output is correct
34 Correct 0 ms 336 KB Output is correct
35 Correct 0 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 0 ms 336 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 0 ms 208 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 0 ms 208 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 0 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 0 ms 336 KB Output is correct
33 Correct 0 ms 208 KB Output is correct
34 Correct 0 ms 336 KB Output is correct
35 Correct 0 ms 336 KB Output is correct
36 Correct 7 ms 1488 KB Output is correct
37 Correct 12 ms 2348 KB Output is correct
38 Correct 9 ms 1568 KB Output is correct
39 Correct 12 ms 2448 KB Output is correct
40 Correct 12 ms 1608 KB Output is correct
41 Correct 20 ms 4788 KB Output is correct
42 Correct 9 ms 1444 KB Output is correct
43 Correct 9 ms 1444 KB Output is correct
44 Correct 8 ms 1472 KB Output is correct
45 Correct 10 ms 1476 KB Output is correct
46 Correct 9 ms 1460 KB Output is correct
47 Correct 14 ms 2360 KB Output is correct
48 Correct 11 ms 1956 KB Output is correct
49 Correct 9 ms 1456 KB Output is correct
50 Correct 9 ms 1452 KB Output is correct
51 Correct 9 ms 1480 KB Output is correct
52 Correct 18 ms 4680 KB Output is correct
53 Correct 22 ms 5572 KB Output is correct
54 Correct 23 ms 5552 KB Output is correct
55 Correct 9 ms 1968 KB Output is correct
56 Correct 9 ms 2084 KB Output is correct
57 Correct 23 ms 4636 KB Output is correct
58 Correct 19 ms 4780 KB Output is correct
59 Correct 19 ms 4680 KB Output is correct
60 Correct 22 ms 5532 KB Output is correct
61 Correct 22 ms 5556 KB Output is correct
62 Correct 22 ms 5524 KB Output is correct
63 Correct 22 ms 5532 KB Output is correct
64 Correct 11 ms 1972 KB Output is correct
65 Correct 10 ms 1944 KB Output is correct
66 Correct 10 ms 2048 KB Output is correct
67 Correct 9 ms 1992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4026 ms 7504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4099 ms 1588 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 0 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 0 ms 336 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 0 ms 208 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 0 ms 208 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 0 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 0 ms 336 KB Output is correct
33 Correct 0 ms 208 KB Output is correct
34 Correct 0 ms 336 KB Output is correct
35 Correct 0 ms 336 KB Output is correct
36 Correct 7 ms 1488 KB Output is correct
37 Correct 12 ms 2348 KB Output is correct
38 Correct 9 ms 1568 KB Output is correct
39 Correct 12 ms 2448 KB Output is correct
40 Correct 12 ms 1608 KB Output is correct
41 Correct 20 ms 4788 KB Output is correct
42 Correct 9 ms 1444 KB Output is correct
43 Correct 9 ms 1444 KB Output is correct
44 Correct 8 ms 1472 KB Output is correct
45 Correct 10 ms 1476 KB Output is correct
46 Correct 9 ms 1460 KB Output is correct
47 Correct 14 ms 2360 KB Output is correct
48 Correct 11 ms 1956 KB Output is correct
49 Correct 9 ms 1456 KB Output is correct
50 Correct 9 ms 1452 KB Output is correct
51 Correct 9 ms 1480 KB Output is correct
52 Correct 18 ms 4680 KB Output is correct
53 Correct 22 ms 5572 KB Output is correct
54 Correct 23 ms 5552 KB Output is correct
55 Correct 9 ms 1968 KB Output is correct
56 Correct 9 ms 2084 KB Output is correct
57 Correct 23 ms 4636 KB Output is correct
58 Correct 19 ms 4780 KB Output is correct
59 Correct 19 ms 4680 KB Output is correct
60 Correct 22 ms 5532 KB Output is correct
61 Correct 22 ms 5556 KB Output is correct
62 Correct 22 ms 5524 KB Output is correct
63 Correct 22 ms 5532 KB Output is correct
64 Correct 11 ms 1972 KB Output is correct
65 Correct 10 ms 1944 KB Output is correct
66 Correct 10 ms 2048 KB Output is correct
67 Correct 9 ms 1992 KB Output is correct
68 Execution timed out 4026 ms 7504 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4046 ms 2248 KB Time limit exceeded
2 Halted 0 ms 0 KB -