Submission #828997

# Submission time Handle Problem Language Result Execution time Memory
828997 2023-08-18T00:07:47 Z arnold518 Radio Towers (IOI22_towers) C++17
17 / 100
883 ms 11792 KB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;
const int INF = 1e9+7;

int N, A[MAXN+10], cnt;
vector<int> B;

void init(int _N, vector<int> _H)
{
	N=_N;
	for(int i=1; i<=N; i++) A[i]=_H[i-1];

	vector<int> V;
	V.push_back(1);
	for(int i=2; i<=N; i++)
	{
		if(V.size()%2)
		{
			if(A[V.back()]<A[i]) V.push_back(i);
			else V.back()=i;
		}
		else
		{
			if(A[V.back()]>A[i]) V.push_back(i);
			else V.back()=i;
		}
	}
	if(V.size()%2==0) V.pop_back();

	set<int> S;
	set<pii> S2;
	for(int i=0; i<V.size(); i++) S.insert(V[i]);
	for(int i=0; i+1<V.size(); i++) S2.insert({abs(A[V[i+1]]-A[V[i]]), V[i]});
	cnt=V.size()/2+1;
	
	while(!S2.empty())
	{
		//for(auto it : S) printf("%d ", A[it]); printf("\n");
		//for(auto it : S2) printf("%d %d / ", it.first, it.second); printf("\n");
		auto [val, p] = *S2.begin(); S2.erase(S2.begin());
		B.push_back(val);
		auto it=S.find(p);
		int l=-1, r=-1;

		if(it!=S.begin())
		{
			int t1=*prev(it), t2=*it;
			S2.erase({abs(A[t1]-A[t2]), t1});
			l=t1;
		}
		if(next(next(it))!=S.end())
		{
			int t1=*next(it), t2=*next(next(it));
			S2.erase({abs(A[t1]-A[t2]), t1});
			r=t2;
		}
		if(l!=-1 && r!=-1) S2.insert({abs(A[r]-A[l]), l});

		S.erase(*next(it));
		S.erase(it);
	}

	//for(auto it : B) printf("%d ", it);
}

int max_towers(int L, int R, int D) 
{
	L++; R++;
	return cnt-(lower_bound(B.begin(), B.end(), D)-B.begin());
}

Compilation message

towers.cpp: In function 'void init(int, std::vector<int>)':
towers.cpp:39:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for(int i=0; i<V.size(); i++) S.insert(V[i]);
      |               ~^~~~~~~~~
towers.cpp:40:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |  for(int i=0; i+1<V.size(); i++) S2.insert({abs(A[V[i+1]]-A[V[i]]), V[i]});
      |               ~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 383 ms 976 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 208 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 208 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 558 ms 8096 KB 1st lines differ - on the 1st token, expected: '11903', found: '33010'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 219 ms 2192 KB Output is correct
2 Correct 707 ms 8360 KB Output is correct
3 Correct 883 ms 8224 KB Output is correct
4 Correct 769 ms 11792 KB Output is correct
5 Correct 718 ms 11608 KB Output is correct
6 Correct 757 ms 11688 KB Output is correct
7 Correct 796 ms 11700 KB Output is correct
8 Correct 462 ms 1480 KB Output is correct
9 Correct 558 ms 1360 KB Output is correct
10 Correct 605 ms 1360 KB Output is correct
11 Correct 640 ms 1452 KB Output is correct
12 Correct 75 ms 8128 KB Output is correct
13 Correct 124 ms 11620 KB Output is correct
14 Correct 118 ms 11680 KB Output is correct
15 Correct 8 ms 1360 KB Output is correct
16 Correct 8 ms 1348 KB Output is correct
17 Correct 74 ms 7948 KB Output is correct
18 Correct 79 ms 8152 KB Output is correct
19 Correct 75 ms 8316 KB Output is correct
20 Correct 120 ms 11632 KB Output is correct
21 Correct 118 ms 11668 KB Output is correct
22 Correct 150 ms 11784 KB Output is correct
23 Correct 124 ms 11672 KB Output is correct
24 Correct 8 ms 1456 KB Output is correct
25 Correct 9 ms 1480 KB Output is correct
26 Correct 8 ms 1444 KB Output is correct
27 Correct 8 ms 1456 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 2 ms 464 KB Output is correct
30 Correct 2 ms 464 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 1 ms 208 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 2 ms 464 KB Output is correct
37 Correct 2 ms 464 KB Output is correct
38 Correct 2 ms 464 KB Output is correct
39 Correct 2 ms 464 KB Output is correct
40 Correct 1 ms 208 KB Output is correct
41 Correct 0 ms 208 KB Output is correct
42 Correct 1 ms 208 KB Output is correct
43 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 208 KB 1st lines differ - on the 1st token, expected: '13', found: '131'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 383 ms 976 KB 1st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -