Submission #1075470

# Submission time Handle Problem Language Result Execution time Memory
1075470 2024-08-26T06:45:22 Z ProtonDecay314 Sprinklers (CEOI24_sprinklers) C++17
20 / 100
2000 ms 1904 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<bool> vb;
typedef set<ll> sll;
#define IOS cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false)
#define INF(dtype) numeric_limits<dtype>::max()
#define NINF(dtype) numeric_limits<dtype>::min()
#define fi first
#define se second

typedef pair<int, vb> pib;

pib solve_n1(int n, int m, const vi& s, const vi& f) {
    vb config(n, false);

    // Case 1: n == 1

    bool less_exists = false;
    bool greater_exists = false;

    int spos = s[0];

    int ans = 0;

    for(int fv : f) {
        if(fv < spos) {
            less_exists = true;
            ans = max(ans, spos - fv);
        } else if(fv > spos) {
            greater_exists = true;
            ans = max(ans, fv - spos);
        }
    }

    config[0] = greater_exists;

    if(less_exists && greater_exists) return {-1, config};
    return {ans, config};
}

pib solve(int n, int m, const vi& s, const vi& f) {
    if(n == 1) {
        return solve_n1(n, m, s, f);
    }

    int ans_config_mask = 0;
    int ans = INF(int);
    for(int mask = 0; mask < (1 << n); mask++) {
        int cost = 0;

        for(int i = 0; i < m; i++) {
            int min_cost = INF(int);

            for(int j = 0; j < n; j++) {
                if((mask >> j) & 0b1) {
                    // points to right
                    if(f[i] >= s[j]) min_cost = min(min_cost, f[i] - s[j]);
                } else {
                    // points to left
                    if(f[i] <= s[j]) min_cost = min(min_cost, s[j] - f[i]);
                }
            }

            cost = max(cost, min_cost);
        }

        if(cost < ans) {
            ans = cost;
            ans_config_mask = mask;
        }
    }

    vb config(n, false);

    for(int i = 0; i < n; i++) config[i] = (ans_config_mask >> i) & 0b1;

    return {ans, config};
}

int main() {
    IOS;

    int n, m;
    cin >> n >> m;

    vi s(n, 0);
    vi f(m, 0);

    for(int& sv : s) cin >> sv;
    for(int& fv : f) cin >> fv;

    auto [ans, config] = solve(n, m, s, f);

    cout << ans << "\n";

    if(ans != -1) {
        for(const bool& b : config) cout << (b ? 'R' : 'L');
        cout << "\n";
    }
    cout << flush;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 6 ms 1372 KB Correct
3 Correct 0 ms 348 KB Correct
4 Correct 8 ms 1744 KB Correct
5 Correct 8 ms 1628 KB Correct
6 Correct 1 ms 452 KB Correct
7 Correct 1 ms 348 KB Correct
8 Correct 1 ms 604 KB Correct
9 Correct 0 ms 604 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Correct
2 Execution timed out 2037 ms 1880 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 6 ms 344 KB Correct
4 Correct 1 ms 348 KB Correct
5 Correct 10 ms 348 KB Correct
6 Correct 12 ms 344 KB Correct
7 Correct 1 ms 348 KB Correct
8 Correct 10 ms 348 KB Correct
9 Correct 10 ms 472 KB Correct
10 Correct 10 ms 348 KB Correct
11 Correct 2 ms 460 KB Correct
12 Correct 11 ms 348 KB Correct
13 Correct 10 ms 348 KB Correct
14 Correct 1 ms 348 KB Correct
15 Correct 9 ms 348 KB Correct
16 Correct 7 ms 468 KB Correct
17 Correct 7 ms 344 KB Correct
18 Correct 7 ms 348 KB Correct
19 Correct 1 ms 348 KB Correct
20 Correct 1 ms 348 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Correct
2 Execution timed out 2028 ms 1904 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Correct
2 Correct 0 ms 348 KB Correct
3 Correct 6 ms 1372 KB Correct
4 Correct 0 ms 348 KB Correct
5 Correct 8 ms 1744 KB Correct
6 Correct 8 ms 1628 KB Correct
7 Correct 1 ms 452 KB Correct
8 Correct 1 ms 348 KB Correct
9 Correct 1 ms 604 KB Correct
10 Correct 0 ms 604 KB Correct
11 Execution timed out 2037 ms 1880 KB Time limit exceeded
12 Halted 0 ms 0 KB -