답안 #1039624

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039624 2024-07-31T06:08:00 Z 박영우(#11029) Sprinklers (CEOI24_sprinklers) C++17
9 / 100
134 ms 7248 KB
//#define LOCAL
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<short, short> pss;
#define MAX 1010101
#define MAXS 20
#define INF 1'000'000'010'000'000'000
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define TC 0
#ifdef LOCAL
#define DEBUG(a) cout<<a
#else
#define DEBUG(...) 
#endif
int S[MAX];
int F[MAX];
int dp[2][MAX];
int ans[MAX];
int path[2][MAX];
int N, M;
int findpv(int x) {
	int ind = lower_bound(F + 1, F + M + 1, x) - F;
	ind--;
	return ind;
}
int findne(int x) {
	int ind = upper_bound(F + 1, F + M + 1, x) - F;
	return ind;
}
bool chk(int m) {
	if (S[1] - m <= F[1]) dp[0][1] = findne(S[1]);
	else dp[0][1] = 0;
	if (S[1] <= F[1]) dp[1][1] = findne(S[1] + m);
	else dp[1][1] = 1;
	path[0][1] = 0;
	path[1][1] = 1;
	int i;
	DEBUG('m' << m << ln);
	for (i = 2; i <= N; i++) {
		dp[0][i] = dp[1][i] = 0;
		if (dp[0][i - 1]) {
			if (F[dp[0][i - 1]] < S[i]) {
				dp[1][i] = dp[0][i - 1];
				path[1][i] = 0;
				if (S[i] - F[dp[0][i - 1]] <= m) {
					dp[0][i] = findne(S[i]);
					path[0][i] = 0;
				}
			}
			else {
				dp[1][i] = findne(S[i] + m);
				path[1][i] = 0;
			}
		}
		if (dp[1][i - 1]) {
			if (F[dp[1][i - 1]] < S[i]) {
				if (dp[1][i] < dp[1][i - 1]) {
					dp[1][i] = dp[1][i - 1];
					path[1][i] = 1;
				}
				if (S[i] - F[dp[1][i - 1]] <= m) {
					int nv = findne(S[i - 1] + m);
					if (dp[0][i] < nv) {
						dp[0][i] = nv;
						path[0][i] = 1;
					}
				}
			}
			else {
				int nv = findne(S[i] + m);
				if (dp[1][i] < nv) {
					dp[1][i] = nv;
					path[1][i] = 1;
				}
			}
		}
	}
	for (i = 1; i <= N; i++) DEBUG(dp[0][i] << bb);
	DEBUG(ln);
	for (i = 1; i <= N; i++) DEBUG(dp[1][i] << bb);
	DEBUG(ln);
	return (dp[0][N] > M || dp[1][N] > M);
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> N >> M;
	int i;
	set<int> st;
	for (i = 1; i <= N; i++) cin >> S[i], st.insert(S[i]);
	for (i = 1; i <= M; i++) {
		cin >> F[i];
		if (st.find(F[i]) != st.end()) {
			i--;
			M--;
		}
	}
	if (!M) {
		cout << "YES" << ln;
		for (i = 1; i <= N; i++) cout << 'L';
		return 0;
	}
	int l, r;
	l = 0;
	r = 1'000'000'100;
	//r = 2;
	while (r - l > 1) {
		int m = l + r >> 1;
		if (chk(m)) r = m;
		else l = m;
	}
	if (!chk(r)) {
		cout << -1;
		return 0;
	}
	cout << r << ln;
	int v = 0;
	if (dp[1][N] > M) v = 1;
	string s;
	for (i = N; i >= 1; i--) {
		if (v) s.push_back('R');
		else s.push_back('L');
		v = path[v][i];
	}
	reverse(s.begin(), s.end());
	cout << s;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:118:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  118 |   int m = l + r >> 1;
      |           ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Correct
2 Correct 0 ms 348 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 5 ms 592 KB Correct
3 Correct 1 ms 2396 KB Correct
4 Correct 6 ms 832 KB Correct
5 Correct 7 ms 860 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 2 ms 348 KB Correct
9 Correct 0 ms 348 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Correct
2 Correct 9 ms 856 KB Correct
3 Correct 8 ms 876 KB Correct
4 Correct 105 ms 5712 KB Correct
5 Correct 125 ms 5716 KB Correct
6 Correct 0 ms 2396 KB Correct
7 Correct 0 ms 2396 KB Correct
8 Correct 57 ms 4120 KB Correct
9 Correct 52 ms 4432 KB Correct
10 Correct 100 ms 7248 KB Correct
11 Correct 45 ms 4660 KB Correct
12 Correct 52 ms 2900 KB Correct
13 Correct 134 ms 5200 KB Correct
14 Correct 118 ms 5456 KB Correct
15 Correct 109 ms 5548 KB Correct
16 Correct 114 ms 6484 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Correct
2 Correct 0 ms 348 KB Correct
3 Incorrect 1 ms 2392 KB User solution is worse than jury's solution
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Correct
2 Incorrect 20 ms 1444 KB User solution is worse than jury's solution
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 5 ms 592 KB Correct
4 Correct 1 ms 2396 KB Correct
5 Correct 6 ms 832 KB Correct
6 Correct 7 ms 860 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 0 ms 348 KB Correct
9 Correct 2 ms 348 KB Correct
10 Correct 0 ms 348 KB Correct
11 Correct 9 ms 856 KB Correct
12 Correct 8 ms 876 KB Correct
13 Correct 105 ms 5712 KB Correct
14 Correct 125 ms 5716 KB Correct
15 Correct 0 ms 2396 KB Correct
16 Correct 0 ms 2396 KB Correct
17 Correct 57 ms 4120 KB Correct
18 Correct 52 ms 4432 KB Correct
19 Correct 100 ms 7248 KB Correct
20 Correct 45 ms 4660 KB Correct
21 Correct 52 ms 2900 KB Correct
22 Correct 134 ms 5200 KB Correct
23 Correct 118 ms 5456 KB Correct
24 Correct 109 ms 5548 KB Correct
25 Correct 114 ms 6484 KB Correct
26 Incorrect 1 ms 2392 KB User solution is worse than jury's solution
27 Halted 0 ms 0 KB -