답안 #1077242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077242 2024-08-27T03:53:53 Z pawned Sprinklers (CEOI24_sprinklers) C++17
9 / 100
917 ms 8788 KB
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

const char nl = '\n';

void fastIO() {
	ios::sync_with_stdio(false);
	cin.tie(0);
}

const int MAX = 1e5 + 5;

int N, M;

vector<ll> a(MAX);	// sprinklers
vector<ll> b(MAX);	// flowers

string check(ll K) {	// width is K
	set<ll> all;
	for (int i = 0; i < M; i++) {
		all.insert(b[i]);
	}
	string res = "";
	for (int i = 0; i < N; i++) {
//		cout<<"at "<<i<<endl;
		if (all.size() == 0)
			break;
		auto it = all.begin();
		ll val = (*it);	// leftmost flower
//		cout<<"val: "<<val<<endl;
		if (val < a[i] - K)
			return "!";
		if (val < a[i]) {
			// cover all from a[i]-K to a[i]
			while (all.size() > 0 && (*(all.begin())) <= a[i])
				all.erase(*(all.begin()));
			res += 'L';
		}
		else {
			while (all.size() > 0 && (*(all.begin())) <= a[i] + K)
				all.erase(*(all.begin()));
			res += 'R';
		}
/*		cout<<"remaining: ";
		for (ll x : all)
			cout<<x<<" ";
		cout<<endl;*/
	}
	while (res.size() < N)
		res += 'L';
	if (all.size() == 0)
		return res;
	return "!";
}

int main() {
	fastIO();
	cin>>N>>M;
	for (int i = 0; i < N; i++) {
		cin>>a[i];
	}
	for (int i = 0; i < M; i++) {
		cin>>b[i];
	}
//	cout<<check(0)<<endl;
	ll low = 0;
	ll high = 1e18;
	ll ans = -1;	// minimum radius to water all flowers
	string ansr = "";
	while (low <= high) {	// false, false, false, true, true, true
		ll mid = (low + high) / 2;
		string res = check(mid);
		if (res != "!") {
			ans = mid;
			ansr = res;
			high = mid - 1;
		}
		else {
			low = mid + 1;
		}
	}
//	cout<<"ANSWER: ";
	cout<<ans<<endl;
	if (ans != -1)
		cout<<ansr<<endl;
}

Compilation message

Main.cpp: In function 'std::string check(ll)':
Main.cpp:58:20: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   58 |  while (res.size() < N)
      |         ~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1880 KB Correct
2 Correct 1 ms 1884 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Correct
2 Correct 562 ms 5848 KB Correct
3 Correct 1 ms 1880 KB Correct
4 Correct 738 ms 7784 KB Correct
5 Correct 675 ms 7684 KB Correct
6 Correct 1 ms 1884 KB Correct
7 Correct 1 ms 1884 KB Correct
8 Correct 112 ms 3116 KB Correct
9 Correct 1 ms 1884 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1880 KB Correct
2 Correct 711 ms 6036 KB Correct
3 Correct 24 ms 2396 KB Correct
4 Correct 887 ms 8788 KB Correct
5 Correct 917 ms 8784 KB Correct
6 Correct 1 ms 1880 KB Correct
7 Correct 1 ms 1884 KB Correct
8 Correct 466 ms 5292 KB Correct
9 Correct 538 ms 5716 KB Correct
10 Correct 858 ms 7760 KB Correct
11 Correct 24 ms 3332 KB Correct
12 Correct 782 ms 7332 KB Correct
13 Correct 548 ms 5712 KB Correct
14 Correct 588 ms 6364 KB Correct
15 Correct 577 ms 6736 KB Correct
16 Correct 464 ms 5216 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1880 KB Correct
2 Correct 1 ms 1884 KB Correct
3 Correct 3 ms 1880 KB Correct
4 Correct 2 ms 1884 KB Correct
5 Incorrect 4 ms 1884 KB User solution is worse than jury's solution
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1880 KB Correct
2 Correct 721 ms 5980 KB Correct
3 Incorrect 914 ms 8448 KB User solution is worse than jury's solution
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1880 KB Correct
2 Correct 1 ms 1884 KB Correct
3 Correct 562 ms 5848 KB Correct
4 Correct 1 ms 1880 KB Correct
5 Correct 738 ms 7784 KB Correct
6 Correct 675 ms 7684 KB Correct
7 Correct 1 ms 1884 KB Correct
8 Correct 1 ms 1884 KB Correct
9 Correct 112 ms 3116 KB Correct
10 Correct 1 ms 1884 KB Correct
11 Correct 711 ms 6036 KB Correct
12 Correct 24 ms 2396 KB Correct
13 Correct 887 ms 8788 KB Correct
14 Correct 917 ms 8784 KB Correct
15 Correct 1 ms 1880 KB Correct
16 Correct 1 ms 1884 KB Correct
17 Correct 466 ms 5292 KB Correct
18 Correct 538 ms 5716 KB Correct
19 Correct 858 ms 7760 KB Correct
20 Correct 24 ms 3332 KB Correct
21 Correct 782 ms 7332 KB Correct
22 Correct 548 ms 5712 KB Correct
23 Correct 588 ms 6364 KB Correct
24 Correct 577 ms 6736 KB Correct
25 Correct 464 ms 5216 KB Correct
26 Correct 3 ms 1880 KB Correct
27 Correct 2 ms 1884 KB Correct
28 Incorrect 4 ms 1884 KB User solution is worse than jury's solution
29 Halted 0 ms 0 KB -