제출 #1087799

#제출 시각아이디문제언어결과실행 시간메모리
1087799mychecksedadSprinklers (CEOI24_sprinklers)C++17
26 / 100
174 ms5056 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define en cout << '\n'
#define vi vector<int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
const int N = 1e5+100;


int n, m, a[N], b[N];
int get(int l, int r){
	if(r < l) return 0;
	return upper_bound(b+1, b+1+m, r) - lower_bound(b+1, b+1+m, l);
}
void solve(){
	cin >> n >> m;
	vector<pii> v;
	for(int i = 1; i <= n; ++i){
		cin >> a[i];
		v.pb({a[i], 1});
	}
	for(int i = 1; i <= m; ++i){
		cin >> b[i];
		v.pb({b[i], 0});
	}
	sort(all(v));
	string soll;
	int l = 0, r = 1e9, ans = -1;
	while(l <= r){
		int k = l+r>>1;
		string sol = "";
		bool ok = 1;
		int last_covered = -2e9;
		for(int i = 1; i <= n; ++i){
			if(last_covered >= a[i] - 1){
				sol += 'R';
				last_covered = a[i] + k;
				continue;
			}
			int left_uncovered = get(last_covered + 1, a[i] - 1);
			if(left_uncovered > get(a[i] - k, a[i] - 1)){
				ok = 0;
				break;
			}
			if(left_uncovered == 0){
				sol += 'R';
				last_covered = a[i] + k;
			}else{
				if(i + 1 <= n){
					int right_cover = get(a[i] + 1, min(a[i + 1] - 1, a[i] + k));
					if(right_cover == 0){
						sol += 'L';
						last_covered = a[i];
					}else if(right_cover > 0){
						if(a[i + 1] - k < a[i] && left_uncovered <= get(a[i + 1] - k, a[i] - 1)){
							sol += 'R';
							sol += 'L';
							last_covered = a[i] + k;
							++i;
							continue;
						}else{
							sol += 'L';
							last_covered = a[i];
							continue;
						}
					}
				}else{
					sol += 'L';
					last_covered = a[i];
				}
			}
		}
		if(b[m] > last_covered) ok = 0;


		if(ok){
			ans = k;
			soll = sol;
			r = k - 1;
		}else{
			l = k + 1;
		}
	}

	cout << ans << '\n';
	if(ans != -1){
		cout << soll;
	}
}

int main(){
	cin.tie(0); ios::sync_with_stdio(0);
	solve();
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'void solve()':
Main.cpp:34:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |   int k = l+r>>1;
      |           ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...