Submission #1047336

# Submission time Handle Problem Language Result Execution time Memory
1047336 2024-08-07T12:00:06 Z dilanyan Sprinklers (CEOI24_sprinklers) C++17
100 / 100
99 ms 3372 KB
//-------------dilanyan------------\\ 
 
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
 
//------------------Kargpefines--------------------\\ 
 
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
 
void KarginSet(string name = "") {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    if (name.size()) {
        freopen((name + ".in").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    }
}
 
//-------------------KarginConstants------------------\\ 
 
const ll mod = 1e9 + 7;
const ll inf = 2e9;
 
//-------------------KarginCode-----------------------\\ 
 
const int N = 100005, M = 1000005;

int n, m;

int s[N], f[N];
int dp[N];

void KarginSolve() {
    int n, m;
    cin >> n >> m;
    for (int i = 1;i <= n;i++) cin >> s[i];
    for (int i = 1;i <= m;i++) cin >> f[i];
    ll l = 0, r = 1e9, ans = -1;
    vector<pair<int, char>> from(n + 1), bfrom(n + 1);
    while(l <= r) {
        ll mid = (l + r) / 2;
        for (int i = 0;i <= n;i++) dp[i] = 0, bfrom[i] = { 0,'?' };
        for (int i = 0;i < n;i++) {
            if (dp[i] > dp[i + 1]) {
                dp[i + 1] = dp[i];
                bfrom[i + 1] = { i,'L' };
            }
            int lx = s[i + 1] - mid, rx = s[i + 1];
            if (f[dp[i] + 1] >= lx && f[dp[i] + 1] <= rx) {
                int x = upper(f + 1 + dp[i], f + 1 + m, rx) - f - 1;
                if (dp[i + 1] < x) {
                    dp[i + 1] = x;
                    bfrom[i + 1] = { i,'L' };
                }
            }
            lx = s[i + 1], rx = s[i + 1] + mid;
            if (f[dp[i] + 1] >= lx && f[dp[i] + 1] <= rx) {
                int x = upper(f + 1 + dp[i], f + 1 + m, rx) - f - 1;
                if (dp[i + 1] < x) {
                    dp[i + 1] = x;
                    bfrom[i + 1] = { i,'R' };
                }
            }
            if (i + 2 <= n) {
                int llx = s[i + 2] - mid, rrx = s[i + 2];
                if (llx < lx && (f[dp[i] + 1] >= lx && f[dp[i] + 1] <= rx) || (f[dp[i] + 1] >= llx && f[dp[i] + 1] <= rrx)) {
                    int x = upper(f + 1 + dp[i], f + 1 + m, rx) - f - 1;
                    if (dp[i + 2] < x) {
                        dp[i + 2] = x;
                        bfrom[i + 2] = { i,'?' };
                    }
                }
            }
        }
        if (dp[n] == m) {
            r = mid - 1;
            ans = mid;
            swap(from, bfrom);
        }
        else l = mid + 1;
    }
    cout << ans << '\n';
    if (ans == -1) return;
    int x = n;
    vector<char> answ(n + 1);
    while (x > 0) {
        if (from[x].second == '?') {
            answ[x] = 'L', answ[x - 1] = 'R';
            x -= 2;
        }
        else {
            answ[x] = from[x].second;
            x--;
        }
    }
    for (int i = 1;i <= n;i++) cout << answ[i];
}

int main() {
    KarginSet();
    int test = 1;
    //cin >> test;
    while (test--) {
        KarginSolve();
    }
    return 0; 
}

Compilation message

Main.cpp:1:1: warning: multi-line comment [-Wcomment]
    1 | //-------------dilanyan------------\\
      | ^
Main.cpp:8:1: warning: multi-line comment [-Wcomment]
    8 | //------------------Kargpefines--------------------\\
      | ^
Main.cpp:27:1: warning: multi-line comment [-Wcomment]
   27 | //-------------------KarginConstants------------------\\
      | ^
Main.cpp:32:1: warning: multi-line comment [-Wcomment]
   32 | //-------------------KarginCode-----------------------\\
      | ^
Main.cpp: In function 'void KarginSolve()':
Main.cpp:74:30: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   74 |                 if (llx < lx && (f[dp[i] + 1] >= lx && f[dp[i] + 1] <= rx) || (f[dp[i] + 1] >= llx && f[dp[i] + 1] <= rrx)) {
      |                     ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'void KarginSet(std::string)':
Main.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen((name + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 0 ms 348 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 4 ms 604 KB Correct
3 Correct 0 ms 348 KB Correct
4 Correct 5 ms 604 KB Correct
5 Correct 5 ms 684 KB Correct
6 Correct 1 ms 348 KB Correct
7 Correct 0 ms 348 KB Correct
8 Correct 1 ms 348 KB Correct
9 Correct 0 ms 348 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 6 ms 780 KB Correct
3 Correct 4 ms 604 KB Correct
4 Correct 46 ms 3200 KB Correct
5 Correct 48 ms 3160 KB Correct
6 Correct 1 ms 344 KB Correct
7 Correct 0 ms 600 KB Correct
8 Correct 34 ms 3164 KB Correct
9 Correct 26 ms 3184 KB Correct
10 Correct 25 ms 3160 KB Correct
11 Correct 18 ms 2904 KB Correct
12 Correct 23 ms 1628 KB Correct
13 Correct 37 ms 3164 KB Correct
14 Correct 45 ms 3152 KB Correct
15 Correct 43 ms 3156 KB Correct
16 Correct 35 ms 3080 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 1 ms 348 KB Correct
4 Correct 0 ms 348 KB Correct
5 Correct 0 ms 392 KB Correct
6 Correct 0 ms 348 KB Correct
7 Correct 1 ms 344 KB Correct
8 Correct 0 ms 348 KB Correct
9 Correct 0 ms 348 KB Correct
10 Correct 0 ms 428 KB Correct
11 Correct 0 ms 348 KB Correct
12 Correct 0 ms 348 KB Correct
13 Correct 0 ms 348 KB Correct
14 Correct 0 ms 348 KB Correct
15 Correct 0 ms 348 KB Correct
16 Correct 0 ms 348 KB Correct
17 Correct 0 ms 348 KB Correct
18 Correct 0 ms 348 KB Correct
19 Correct 0 ms 348 KB Correct
20 Correct 0 ms 348 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 15 ms 1076 KB Correct
3 Correct 76 ms 3188 KB Correct
4 Correct 77 ms 3204 KB Correct
5 Correct 79 ms 3188 KB Correct
6 Correct 76 ms 3160 KB Correct
7 Correct 77 ms 3164 KB Correct
8 Correct 75 ms 3188 KB Correct
9 Correct 76 ms 3164 KB Correct
10 Correct 81 ms 3208 KB Correct
11 Correct 77 ms 3204 KB Correct
12 Correct 0 ms 344 KB Correct
13 Correct 0 ms 344 KB Correct
14 Correct 18 ms 2904 KB Correct
15 Correct 36 ms 2824 KB Correct
16 Correct 19 ms 2908 KB Correct
17 Correct 26 ms 3164 KB Correct
18 Correct 27 ms 3312 KB Correct
19 Correct 31 ms 3164 KB Correct
20 Correct 99 ms 3164 KB Correct
21 Correct 85 ms 3188 KB Correct
22 Correct 57 ms 3160 KB Correct
23 Correct 59 ms 3212 KB Correct
24 Correct 57 ms 3204 KB Correct
25 Correct 64 ms 3208 KB Correct
26 Correct 33 ms 2380 KB Correct
27 Correct 31 ms 1368 KB Correct
28 Correct 54 ms 3156 KB Correct
29 Correct 73 ms 3152 KB Correct
30 Correct 47 ms 3152 KB Correct
31 Correct 53 ms 2648 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 4 ms 604 KB Correct
4 Correct 0 ms 348 KB Correct
5 Correct 5 ms 604 KB Correct
6 Correct 5 ms 684 KB Correct
7 Correct 1 ms 348 KB Correct
8 Correct 0 ms 348 KB Correct
9 Correct 1 ms 348 KB Correct
10 Correct 0 ms 348 KB Correct
11 Correct 6 ms 780 KB Correct
12 Correct 4 ms 604 KB Correct
13 Correct 46 ms 3200 KB Correct
14 Correct 48 ms 3160 KB Correct
15 Correct 1 ms 344 KB Correct
16 Correct 0 ms 600 KB Correct
17 Correct 34 ms 3164 KB Correct
18 Correct 26 ms 3184 KB Correct
19 Correct 25 ms 3160 KB Correct
20 Correct 18 ms 2904 KB Correct
21 Correct 23 ms 1628 KB Correct
22 Correct 37 ms 3164 KB Correct
23 Correct 45 ms 3152 KB Correct
24 Correct 43 ms 3156 KB Correct
25 Correct 35 ms 3080 KB Correct
26 Correct 1 ms 348 KB Correct
27 Correct 0 ms 348 KB Correct
28 Correct 0 ms 392 KB Correct
29 Correct 0 ms 348 KB Correct
30 Correct 1 ms 344 KB Correct
31 Correct 0 ms 348 KB Correct
32 Correct 0 ms 348 KB Correct
33 Correct 0 ms 428 KB Correct
34 Correct 0 ms 348 KB Correct
35 Correct 0 ms 348 KB Correct
36 Correct 0 ms 348 KB Correct
37 Correct 0 ms 348 KB Correct
38 Correct 0 ms 348 KB Correct
39 Correct 0 ms 348 KB Correct
40 Correct 0 ms 348 KB Correct
41 Correct 0 ms 348 KB Correct
42 Correct 0 ms 348 KB Correct
43 Correct 0 ms 348 KB Correct
44 Correct 15 ms 1076 KB Correct
45 Correct 76 ms 3188 KB Correct
46 Correct 77 ms 3204 KB Correct
47 Correct 79 ms 3188 KB Correct
48 Correct 76 ms 3160 KB Correct
49 Correct 77 ms 3164 KB Correct
50 Correct 75 ms 3188 KB Correct
51 Correct 76 ms 3164 KB Correct
52 Correct 81 ms 3208 KB Correct
53 Correct 77 ms 3204 KB Correct
54 Correct 0 ms 344 KB Correct
55 Correct 0 ms 344 KB Correct
56 Correct 18 ms 2904 KB Correct
57 Correct 36 ms 2824 KB Correct
58 Correct 19 ms 2908 KB Correct
59 Correct 26 ms 3164 KB Correct
60 Correct 27 ms 3312 KB Correct
61 Correct 31 ms 3164 KB Correct
62 Correct 99 ms 3164 KB Correct
63 Correct 85 ms 3188 KB Correct
64 Correct 57 ms 3160 KB Correct
65 Correct 59 ms 3212 KB Correct
66 Correct 57 ms 3204 KB Correct
67 Correct 64 ms 3208 KB Correct
68 Correct 33 ms 2380 KB Correct
69 Correct 31 ms 1368 KB Correct
70 Correct 54 ms 3156 KB Correct
71 Correct 73 ms 3152 KB Correct
72 Correct 47 ms 3152 KB Correct
73 Correct 53 ms 2648 KB Correct
74 Correct 8 ms 860 KB Correct
75 Correct 75 ms 3196 KB Correct
76 Correct 79 ms 3160 KB Correct
77 Correct 0 ms 344 KB Correct
78 Correct 24 ms 3372 KB Correct
79 Correct 25 ms 3164 KB Correct
80 Correct 23 ms 3160 KB Correct
81 Correct 21 ms 2904 KB Correct
82 Correct 18 ms 2908 KB Correct
83 Correct 21 ms 2896 KB Correct
84 Correct 10 ms 632 KB Correct
85 Correct 54 ms 3072 KB Correct
86 Correct 58 ms 3152 KB Correct
87 Correct 50 ms 2648 KB Correct
88 Correct 6 ms 604 KB Correct
89 Correct 5 ms 648 KB Correct