# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1039597 |
2024-07-31T05:12:37 Z |
정희우(#10993) |
Sprinklers (CEOI24_sprinklers) |
C++17 |
|
255 ms |
4624 KB |
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using lint = long long;
using intp = pair<int,int>;
using vint = vector<int>;
const int MAX_N=100010;
const int MAX_D=1000000010;
int n,m;
int sarr[MAX_N],farr[MAX_N];
int ll[MAX_N],lr[MAX_N],rl[MAX_N],rr[MAX_N];
int dt[MAX_N];
char ans[MAX_N];
bool solve(int d)
{
for(int i=0;i<n;i++)
{
ll[i]=lower_bound(farr,farr+m,sarr[i]-d)-farr;
rr[i]=upper_bound(farr,farr+m,sarr[i]+d)-farr;
}
fill(dt,dt+n+1,0);
for(int i=0;i<n;i++)
{
if(dt[i]>=rl[i])dt[i+1]=max(dt[i+1],rr[i]);
if(i<=n-2 && dt[i]>=ll[i+1])dt[i+2]=max(dt[i+2],rr[i]);
if(dt[i]>=ll[i])dt[i+1]=max(dt[i+1],lr[i]);
else return false;
}
return dt[n]==m;
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n >> m;
for(int i=0;i<n;i++)
cin >> sarr[i];
for(int i=0;i<m;i++)
cin >> farr[i];
m=unique(farr,farr+m)-farr;
for(int i=0;i<n;i++)
{
lr[i]=upper_bound(farr,farr+m,sarr[i])-farr;
rl[i]=lower_bound(farr,farr+m,sarr[i])-farr;
}
int lb=0,ub=MAX_D;
while(lb<ub)
{
int d=(lb+ub)/2;
if(solve(d))ub=d;
else lb=d+1;
}
if(lb==MAX_D)
{
cout << -1;
return 0;
}
solve(lb);
for(int i=n;i>0;)
{
if(dt[i]==rr[i-1] && dt[i-1]>=rl[i-1])
ans[--i]='R';
else if(i>=2 && dt[i]==rr[i-2] && dt[i-2]>=ll[i-1])
{
ans[--i]='L';
ans[--i]='R';
}
else
ans[--i]='L';
}
cout << lb << '\n' << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Correct |
2 |
Correct |
0 ms |
2396 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Correct |
2 |
Correct |
7 ms |
604 KB |
Correct |
3 |
Correct |
0 ms |
348 KB |
Correct |
4 |
Correct |
6 ms |
860 KB |
Correct |
5 |
Correct |
7 ms |
2652 KB |
Correct |
6 |
Correct |
1 ms |
2396 KB |
Correct |
7 |
Correct |
0 ms |
2396 KB |
Correct |
8 |
Correct |
3 ms |
2396 KB |
Correct |
9 |
Correct |
0 ms |
2396 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Correct |
2 |
Correct |
9 ms |
2660 KB |
Correct |
3 |
Correct |
16 ms |
2396 KB |
Correct |
4 |
Correct |
182 ms |
3180 KB |
Correct |
5 |
Correct |
179 ms |
3156 KB |
Correct |
6 |
Correct |
1 ms |
2392 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
100 ms |
3176 KB |
Correct |
9 |
Correct |
105 ms |
3184 KB |
Correct |
10 |
Correct |
119 ms |
3164 KB |
Correct |
11 |
Correct |
59 ms |
2900 KB |
Correct |
12 |
Correct |
91 ms |
1624 KB |
Correct |
13 |
Correct |
137 ms |
3032 KB |
Correct |
14 |
Correct |
149 ms |
3152 KB |
Correct |
15 |
Correct |
156 ms |
3156 KB |
Correct |
16 |
Correct |
133 ms |
3056 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Correct |
2 |
Correct |
0 ms |
2396 KB |
Correct |
3 |
Correct |
1 ms |
2392 KB |
Correct |
4 |
Correct |
1 ms |
2396 KB |
Correct |
5 |
Correct |
0 ms |
348 KB |
Correct |
6 |
Correct |
0 ms |
348 KB |
Correct |
7 |
Correct |
0 ms |
348 KB |
Correct |
8 |
Correct |
0 ms |
348 KB |
Correct |
9 |
Correct |
0 ms |
348 KB |
Correct |
10 |
Correct |
0 ms |
348 KB |
Correct |
11 |
Correct |
0 ms |
2396 KB |
Correct |
12 |
Correct |
0 ms |
2396 KB |
Correct |
13 |
Correct |
1 ms |
348 KB |
Correct |
14 |
Correct |
0 ms |
348 KB |
Correct |
15 |
Correct |
1 ms |
344 KB |
Correct |
16 |
Correct |
1 ms |
2396 KB |
Correct |
17 |
Correct |
0 ms |
2396 KB |
Correct |
18 |
Correct |
0 ms |
376 KB |
Correct |
19 |
Correct |
0 ms |
348 KB |
Correct |
20 |
Correct |
1 ms |
2396 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Correct |
2 |
Correct |
38 ms |
2652 KB |
Correct |
3 |
Correct |
214 ms |
3168 KB |
Correct |
4 |
Correct |
255 ms |
4436 KB |
Correct |
5 |
Correct |
227 ms |
4496 KB |
Correct |
6 |
Correct |
219 ms |
4428 KB |
Correct |
7 |
Correct |
220 ms |
4624 KB |
Correct |
8 |
Correct |
220 ms |
4476 KB |
Correct |
9 |
Correct |
218 ms |
4436 KB |
Correct |
10 |
Correct |
217 ms |
4460 KB |
Correct |
11 |
Correct |
205 ms |
4416 KB |
Correct |
12 |
Correct |
1 ms |
348 KB |
Correct |
13 |
Correct |
0 ms |
348 KB |
Correct |
14 |
Correct |
71 ms |
3560 KB |
Correct |
15 |
Correct |
74 ms |
3572 KB |
Correct |
16 |
Correct |
77 ms |
3756 KB |
Correct |
17 |
Correct |
60 ms |
3708 KB |
Correct |
18 |
Correct |
73 ms |
3672 KB |
Correct |
19 |
Correct |
108 ms |
3928 KB |
Correct |
20 |
Correct |
189 ms |
4148 KB |
Correct |
21 |
Correct |
197 ms |
4244 KB |
Correct |
22 |
Correct |
189 ms |
4208 KB |
Correct |
23 |
Correct |
179 ms |
4176 KB |
Correct |
24 |
Correct |
170 ms |
3920 KB |
Correct |
25 |
Correct |
167 ms |
3920 KB |
Correct |
26 |
Correct |
97 ms |
3164 KB |
Correct |
27 |
Correct |
111 ms |
2012 KB |
Correct |
28 |
Correct |
160 ms |
3920 KB |
Correct |
29 |
Correct |
185 ms |
3808 KB |
Correct |
30 |
Correct |
222 ms |
3844 KB |
Correct |
31 |
Correct |
165 ms |
3784 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Correct |
2 |
Correct |
0 ms |
2396 KB |
Correct |
3 |
Correct |
7 ms |
604 KB |
Correct |
4 |
Correct |
0 ms |
348 KB |
Correct |
5 |
Correct |
6 ms |
860 KB |
Correct |
6 |
Correct |
7 ms |
2652 KB |
Correct |
7 |
Correct |
1 ms |
2396 KB |
Correct |
8 |
Correct |
0 ms |
2396 KB |
Correct |
9 |
Correct |
3 ms |
2396 KB |
Correct |
10 |
Correct |
0 ms |
2396 KB |
Correct |
11 |
Correct |
9 ms |
2660 KB |
Correct |
12 |
Correct |
16 ms |
2396 KB |
Correct |
13 |
Correct |
182 ms |
3180 KB |
Correct |
14 |
Correct |
179 ms |
3156 KB |
Correct |
15 |
Correct |
1 ms |
2392 KB |
Correct |
16 |
Correct |
0 ms |
348 KB |
Correct |
17 |
Correct |
100 ms |
3176 KB |
Correct |
18 |
Correct |
105 ms |
3184 KB |
Correct |
19 |
Correct |
119 ms |
3164 KB |
Correct |
20 |
Correct |
59 ms |
2900 KB |
Correct |
21 |
Correct |
91 ms |
1624 KB |
Correct |
22 |
Correct |
137 ms |
3032 KB |
Correct |
23 |
Correct |
149 ms |
3152 KB |
Correct |
24 |
Correct |
156 ms |
3156 KB |
Correct |
25 |
Correct |
133 ms |
3056 KB |
Correct |
26 |
Correct |
1 ms |
2392 KB |
Correct |
27 |
Correct |
1 ms |
2396 KB |
Correct |
28 |
Correct |
0 ms |
348 KB |
Correct |
29 |
Correct |
0 ms |
348 KB |
Correct |
30 |
Correct |
0 ms |
348 KB |
Correct |
31 |
Correct |
0 ms |
348 KB |
Correct |
32 |
Correct |
0 ms |
348 KB |
Correct |
33 |
Correct |
0 ms |
348 KB |
Correct |
34 |
Correct |
0 ms |
2396 KB |
Correct |
35 |
Correct |
0 ms |
2396 KB |
Correct |
36 |
Correct |
1 ms |
348 KB |
Correct |
37 |
Correct |
0 ms |
348 KB |
Correct |
38 |
Correct |
1 ms |
344 KB |
Correct |
39 |
Correct |
1 ms |
2396 KB |
Correct |
40 |
Correct |
0 ms |
2396 KB |
Correct |
41 |
Correct |
0 ms |
376 KB |
Correct |
42 |
Correct |
0 ms |
348 KB |
Correct |
43 |
Correct |
1 ms |
2396 KB |
Correct |
44 |
Correct |
38 ms |
2652 KB |
Correct |
45 |
Correct |
214 ms |
3168 KB |
Correct |
46 |
Correct |
255 ms |
4436 KB |
Correct |
47 |
Correct |
227 ms |
4496 KB |
Correct |
48 |
Correct |
219 ms |
4428 KB |
Correct |
49 |
Correct |
220 ms |
4624 KB |
Correct |
50 |
Correct |
220 ms |
4476 KB |
Correct |
51 |
Correct |
218 ms |
4436 KB |
Correct |
52 |
Correct |
217 ms |
4460 KB |
Correct |
53 |
Correct |
205 ms |
4416 KB |
Correct |
54 |
Correct |
1 ms |
348 KB |
Correct |
55 |
Correct |
0 ms |
348 KB |
Correct |
56 |
Correct |
71 ms |
3560 KB |
Correct |
57 |
Correct |
74 ms |
3572 KB |
Correct |
58 |
Correct |
77 ms |
3756 KB |
Correct |
59 |
Correct |
60 ms |
3708 KB |
Correct |
60 |
Correct |
73 ms |
3672 KB |
Correct |
61 |
Correct |
108 ms |
3928 KB |
Correct |
62 |
Correct |
189 ms |
4148 KB |
Correct |
63 |
Correct |
197 ms |
4244 KB |
Correct |
64 |
Correct |
189 ms |
4208 KB |
Correct |
65 |
Correct |
179 ms |
4176 KB |
Correct |
66 |
Correct |
170 ms |
3920 KB |
Correct |
67 |
Correct |
167 ms |
3920 KB |
Correct |
68 |
Correct |
97 ms |
3164 KB |
Correct |
69 |
Correct |
111 ms |
2012 KB |
Correct |
70 |
Correct |
160 ms |
3920 KB |
Correct |
71 |
Correct |
185 ms |
3808 KB |
Correct |
72 |
Correct |
222 ms |
3844 KB |
Correct |
73 |
Correct |
165 ms |
3784 KB |
Correct |
74 |
Correct |
18 ms |
1696 KB |
Correct |
75 |
Correct |
226 ms |
4444 KB |
Correct |
76 |
Correct |
228 ms |
4460 KB |
Correct |
77 |
Correct |
1 ms |
2392 KB |
Correct |
78 |
Correct |
144 ms |
4532 KB |
Correct |
79 |
Correct |
119 ms |
4460 KB |
Correct |
80 |
Correct |
110 ms |
4456 KB |
Correct |
81 |
Correct |
59 ms |
3736 KB |
Correct |
82 |
Correct |
87 ms |
3668 KB |
Correct |
83 |
Correct |
81 ms |
3752 KB |
Correct |
84 |
Correct |
22 ms |
1332 KB |
Correct |
85 |
Correct |
188 ms |
3924 KB |
Correct |
86 |
Correct |
197 ms |
4080 KB |
Correct |
87 |
Correct |
173 ms |
4016 KB |
Correct |
88 |
Correct |
7 ms |
3416 KB |
Correct |
89 |
Correct |
7 ms |
1628 KB |
Correct |