답안 #1070088

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1070088 2024-08-22T11:35:33 Z BigBadBully Sprinklers (CEOI24_sprinklers) C++17
9 / 100
200 ms 12396 KB
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pii pair<int,int>
pii bad = {-1,-1};
const int jonkler = 1e15;
signed main() {
    int n,m;
    cin >> n >> m;
    vector<int> a(n),b(m);
    for (int i = 0; i < n; i++)
        cin >> a[i];

    for (int i = 0; i < m; i++)
        cin >> b[i];
    set<int> as,bs;
    for (int i = 0; i < n; i++)
    {
        as.insert(a[i]);
    }
    for (int i = 0; i < m; i++)
        if (as.find(b[i]) == as.end())
            bs.insert(b[i]);
    vector<int> neu;
    for (int i : bs)
        neu.push_back(i);
    b = neu;
    auto solve = [&](int k)
    {
        queue<pii> all;
        int i = 0,  j = 0;
        
        while(i < n && j < m)
        {
            if (a[i] < b[j])
                all.push({a[i++],1});
            else 
                all.push({b[j++],0});
            
        }
       while (i<n) all.push({a[i++],1});
        while (j<m) all.push({b[j++],0});
        int prev = jonkler;
        int range = -1;
       
        while (all.size())
        {
            auto cur = all.front();
            if (cur.ss)
            {
                if (prev == jonkler)
                range = cur.ff+k;
                else
                {
                    if (prev < cur.ff - k)
                    {
                        return 0;
                    }
                    else
                        prev = jonkler;
                }
            }
            else
            {
                if (cur.ff>range)
                prev = min(prev,cur.ff);
            }
            all.pop();
        }
        if (prev > range && prev != jonkler)
            return 0;
        return 1;
    };
    int l = 0, r = 1e10;
    while(r-l>1)
    {
        int mid = (l+r)/2;
        if (solve(mid))
            r = mid;
        else
            l = mid;
    }
    string ans;
    auto fillstr = [&](int k)
    {
        queue<pii> all;
        int i = 0,  j = 0;
        while(i < n && j < m)
        {
            if (a[i] < b[j])
                all.push({a[i++],1});
            else
                all.push({b[j++],0});
        }
       while (i<n) all.push({a[i++],1});
        while (j<m) all.push({b[j++],0});
        int prev = jonkler;
        int range = -1;
       
        while (all.size())
        {
            auto cur = all.front();
            if (cur.ss)
            {
                if (prev == jonkler)
                {
                    range = cur.ff+k;
                    ans.push_back('R');
                }
                else
                {
                    
                    prev = jonkler;
                    ans.push_back('L');
                }
            }
            else
            {
                if (cur.ff>range)
                prev = min(prev,cur.ff);
            }
            all.pop();
        }
        
    };
    if (r == 1e10)
        cout << "-1\n";
    else
    {
    if (solve(l))
    {
        cout << l << '\n';
        fillstr(l);
        cout << ans << '\n';
      
    }
    else
    {
        cout << r << '\n';
        fillstr(r);
         cout << ans << '\n';
    }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 0 ms 344 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Correct
2 Correct 72 ms 5956 KB Correct
3 Correct 0 ms 344 KB Correct
4 Correct 85 ms 8428 KB Correct
5 Correct 91 ms 8388 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 16 ms 1976 KB Correct
9 Correct 0 ms 348 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 86 ms 6520 KB Correct
3 Correct 12 ms 1164 KB Correct
4 Correct 200 ms 12396 KB Correct
5 Correct 194 ms 12384 KB Correct
6 Correct 0 ms 344 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 154 ms 6736 KB Correct
9 Correct 169 ms 7152 KB Correct
10 Correct 186 ms 10060 KB Correct
11 Correct 84 ms 4500 KB Correct
12 Correct 124 ms 9368 KB Correct
13 Correct 147 ms 8572 KB Correct
14 Correct 160 ms 9672 KB Correct
15 Correct 150 ms 9708 KB Correct
16 Correct 134 ms 7028 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 0 ms 344 KB Correct
3 Correct 1 ms 344 KB Correct
4 Correct 1 ms 348 KB Correct
5 Incorrect 1 ms 348 KB User solution is worse than jury's solution
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Incorrect 102 ms 6476 KB User solution is worse than jury's solution
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 0 ms 344 KB Correct
3 Correct 72 ms 5956 KB Correct
4 Correct 0 ms 344 KB Correct
5 Correct 85 ms 8428 KB Correct
6 Correct 91 ms 8388 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 0 ms 348 KB Correct
9 Correct 16 ms 1976 KB Correct
10 Correct 0 ms 348 KB Correct
11 Correct 86 ms 6520 KB Correct
12 Correct 12 ms 1164 KB Correct
13 Correct 200 ms 12396 KB Correct
14 Correct 194 ms 12384 KB Correct
15 Correct 0 ms 344 KB Correct
16 Correct 0 ms 348 KB Correct
17 Correct 154 ms 6736 KB Correct
18 Correct 169 ms 7152 KB Correct
19 Correct 186 ms 10060 KB Correct
20 Correct 84 ms 4500 KB Correct
21 Correct 124 ms 9368 KB Correct
22 Correct 147 ms 8572 KB Correct
23 Correct 160 ms 9672 KB Correct
24 Correct 150 ms 9708 KB Correct
25 Correct 134 ms 7028 KB Correct
26 Correct 1 ms 344 KB Correct
27 Correct 1 ms 348 KB Correct
28 Incorrect 1 ms 348 KB User solution is worse than jury's solution
29 Halted 0 ms 0 KB -