답안 #1077248

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077248 2024-08-27T04:03:25 Z pawned Sprinklers (CEOI24_sprinklers) C++17
9 / 100
1076 ms 8108 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
	multiset<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;*/
	}
//	cout<<"res: "<<res<<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(6)<<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:59:20: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   59 |  while (res.size() < N)
      |         ~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Correct
2 Correct 1 ms 1884 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Correct
2 Correct 689 ms 5920 KB Correct
3 Correct 1 ms 1884 KB Correct
4 Correct 840 ms 6708 KB Correct
5 Correct 739 ms 7480 KB Correct
6 Correct 1 ms 1884 KB Correct
7 Correct 1 ms 1884 KB Correct
8 Correct 112 ms 3120 KB Correct
9 Correct 2 ms 1884 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Correct
2 Correct 944 ms 7248 KB Correct
3 Correct 31 ms 2136 KB Correct
4 Correct 887 ms 8016 KB Correct
5 Correct 976 ms 8096 KB Correct
6 Correct 1 ms 1884 KB Correct
7 Correct 2 ms 1884 KB Correct
8 Correct 887 ms 8108 KB Correct
9 Correct 852 ms 8104 KB Correct
10 Correct 1076 ms 8096 KB Correct
11 Correct 24 ms 3344 KB Correct
12 Correct 776 ms 6896 KB Correct
13 Correct 608 ms 6008 KB Correct
14 Correct 577 ms 6232 KB Correct
15 Correct 572 ms 6212 KB Correct
16 Correct 573 ms 6016 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Correct
2 Correct 1 ms 1884 KB Correct
3 Correct 3 ms 1884 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 1884 KB Correct
2 Correct 865 ms 7504 KB Correct
3 Incorrect 941 ms 8092 KB User solution is worse than jury's solution
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1884 KB Correct
2 Correct 1 ms 1884 KB Correct
3 Correct 689 ms 5920 KB Correct
4 Correct 1 ms 1884 KB Correct
5 Correct 840 ms 6708 KB Correct
6 Correct 739 ms 7480 KB Correct
7 Correct 1 ms 1884 KB Correct
8 Correct 1 ms 1884 KB Correct
9 Correct 112 ms 3120 KB Correct
10 Correct 2 ms 1884 KB Correct
11 Correct 944 ms 7248 KB Correct
12 Correct 31 ms 2136 KB Correct
13 Correct 887 ms 8016 KB Correct
14 Correct 976 ms 8096 KB Correct
15 Correct 1 ms 1884 KB Correct
16 Correct 2 ms 1884 KB Correct
17 Correct 887 ms 8108 KB Correct
18 Correct 852 ms 8104 KB Correct
19 Correct 1076 ms 8096 KB Correct
20 Correct 24 ms 3344 KB Correct
21 Correct 776 ms 6896 KB Correct
22 Correct 608 ms 6008 KB Correct
23 Correct 577 ms 6232 KB Correct
24 Correct 572 ms 6212 KB Correct
25 Correct 573 ms 6016 KB Correct
26 Correct 3 ms 1884 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 -