답안 #1100614

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100614 2024-10-14T10:32:44 Z crafticat Sprinklers (CEOI24_sprinklers) C++17
27 / 100
992 ms 14628 KB
#include <bits/stdc++.h>

using ll = long long;
using namespace std;
template<typename T>

using V = vector<T>;
using vi = V<ll>;
using vb = V<bool>;
using pi = pair<ll,ll>;


vi water, flowers;
V<bool> types;
set<ll> problems;
constexpr ll inf = 1e9 * 2 + 7;

bool between(ll l, ll r) {
    auto it = problems.upper_bound(l);
    if (it == problems.end() || *it >= r) return true;
    return false;
}

ll pos(V<V<ll>> &dp, ll i, ll lastR, ll r) {
    ll leftR = -1;
    if (i >= 0) {
        for (ll j = 0; j < 3; ++j) {
            if (j == 0) leftR = water[i];
            if (j == 1 && i - 1 >= 0) leftR = water[i - 1] + r;
            if (j == 2) leftR = water[i] + r;
            if (dp[i][j] == -1) continue;
            if (between(leftR, lastR)) return j;
        }
    } else {
       return between(0, lastR) ? 0 : -1;
    }
    return -1;
}

bool ok(ll r) {
    V<V<ll>> dp(water.size() + 1, vi(3,-1));

    for (ll i = 0; i < water.size(); ++i) {
        for (ll j = 0; j < 3; ++j) {
            ll lastR = -1;
            if (j == 0) lastR = water[i] - r;
            if (j == 1 && i - 1 >= 0 && between(water[i - 1] + r, water[i] - r)) lastR = water[i] - r;
            if (j == 2) lastR = water[i];
            dp[i][j] = pos(dp,i - 1 + (j == 1 ? -1 : 0),lastR, r);
        }
    }

    // Backtrace
    ll last = dp[water.size() - 1][2];
    ll i = water.size() - 1;
    if (last == -1) return false;
    while (last != -1) {
        if (last == 1) {
            types.push_back(false);
            if (i - 2 < 0) return true;
            types.push_back(true);
            last = dp[i - 1][last];
            i -= 2;
        } else {
            types.push_back(last == 2);
            if (i - 1 < 0) return true;
            last = dp[i - 1][last];
            i--;
        }
    }
    return true;
}

int main() {

    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    ll n, m; cin >> n >> m;
    water.resize(n + 1);
    flowers.resize(m);

    for (ll i = 0; i < n; ++i) {
        cin >> water[i];
        water[i]++;
    }
    water[n] = inf;
    for (ll i = 0; i < m; ++i) {
        cin >> flowers[i];
        flowers[i]++;
        problems.insert(flowers[i]);
    }

    ll l = 0, r = inf; // Last true
    while (r > l) {
        ll mid = l + (r - l) / 2;
        if (ok(mid)) {
            r = mid;
        } else
            l = mid + 1;
    }

    types.clear();
    ok(l);
    if (l == inf) {
        cout << -1;
        return 0;
    }
    cout << l << "\n";
    types.pop_back();
    std::reverse(types.begin(), types.end());
    for (auto x : types) {
        cout << (x ? "R" : "L");
    }

    return 0;
}

Compilation message

Main.cpp: In function 'bool ok(ll)':
Main.cpp:43:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int, std::allocator<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (ll i = 0; i < water.size(); ++i) {
      |                    ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Correct
2 Correct 1 ms 336 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Correct
2 Incorrect 17 ms 3920 KB Unexpected end of file - token expected
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Correct
2 Correct 30 ms 4176 KB Correct
3 Correct 45 ms 1372 KB Correct
4 Correct 643 ms 12836 KB Correct
5 Correct 731 ms 12964 KB Correct
6 Correct 1 ms 336 KB Correct
7 Correct 1 ms 336 KB Correct
8 Incorrect 519 ms 9012 KB Incorrect string length
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Correct
2 Correct 1 ms 336 KB Correct
3 Correct 1 ms 336 KB Correct
4 Correct 1 ms 336 KB Correct
5 Correct 1 ms 336 KB Correct
6 Correct 1 ms 336 KB Correct
7 Correct 1 ms 464 KB Correct
8 Correct 1 ms 340 KB Correct
9 Correct 1 ms 340 KB Correct
10 Incorrect 1 ms 340 KB Incorrect string length
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Correct
2 Correct 154 ms 4848 KB Correct
3 Correct 928 ms 12732 KB Correct
4 Correct 948 ms 14628 KB Correct
5 Correct 920 ms 14524 KB Correct
6 Correct 972 ms 14612 KB Correct
7 Correct 891 ms 14628 KB Correct
8 Correct 893 ms 14628 KB Correct
9 Correct 948 ms 14624 KB Correct
10 Correct 915 ms 14628 KB Correct
11 Correct 918 ms 14592 KB Correct
12 Correct 1 ms 340 KB Correct
13 Correct 1 ms 340 KB Correct
14 Correct 216 ms 8472 KB Correct
15 Correct 254 ms 8540 KB Correct
16 Correct 253 ms 8524 KB Correct
17 Correct 222 ms 9012 KB Correct
18 Correct 273 ms 9252 KB Correct
19 Correct 422 ms 9764 KB Correct
20 Correct 946 ms 14372 KB Correct
21 Correct 991 ms 14372 KB Correct
22 Correct 910 ms 13836 KB Correct
23 Correct 992 ms 13852 KB Correct
24 Correct 778 ms 12388 KB Correct
25 Correct 763 ms 12256 KB Correct
26 Correct 313 ms 7536 KB Correct
27 Correct 329 ms 5308 KB Correct
28 Correct 800 ms 11912 KB Correct
29 Correct 670 ms 11396 KB Correct
30 Correct 751 ms 11664 KB Correct
31 Correct 944 ms 12788 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Correct
2 Correct 1 ms 336 KB Correct
3 Incorrect 17 ms 3920 KB Unexpected end of file - token expected
4 Halted 0 ms 0 KB -