Submission #1092081

# Submission time Handle Problem Language Result Execution time Memory
1092081 2024-09-23T05:36:56 Z thangdz2k7 Sparklers (JOI17_sparklers) C++17
0 / 100
0 ms 348 KB
// author : thembululquaUwU
// 3.9.2024

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'

using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;

const int N = 1e5 + 5;
const int mod = 1e9 + 7;

void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}

int n, k;
ll t, x[N], b[N];

bool check(int s){
    for (int i = 1; i <= n; ++ i) b[i] = x[i] - t * i * s * 2;
    int bl = k, br = k;
    for (int i = 1; i <= k; ++ i) if (b[i] > b[bl]) bl = i;
    for (int i = k; i <= n; ++ i) if (b[i] < b[br]) br = i;
    int l = k, r = k;
    ll vmax = b[k], vmin = b[k];
    while (bl <= l || r <= br){
        int ol = l, ork = r;
        for (; l >= bl && b[l] >= vmin; -- l) maxl(vmax, b[l]);
        for (; r <= br && b[r] <= vmax; ++ r) minl(vmin, b[r]);
        if (l == ol && r == ork) return false;
    }
    l = 1, r = n;
    vmax = b[l], vmin = b[r];
    while (l <= bl && r >= br){
        int ol = l, ork = r;
        for (; l <= bl && b[l] >= vmin; ++ l) maxl(vmax, b[l]);
        for (; r >= br && b[r] <= vmax; -- r) minl(vmin, b[r]);
        if (l == ol && r == ork) return false;
    }

    return true;
}

void solve(){
    cin >> n >> k >> t;
    for (int i = 1; i <= n; ++ i) cin >> x[i];

    int lo = 0, hi = x[n] / t + 1, ans = hi;
    while (lo <= hi){
        int mid = lo + hi >> 1;
        if (check(mid)) ans = mid, hi = mid - 1;
        else lo = mid + 1;
    }
    cout << ans;
}

int main(){
    if (fopen("pqh.inp", "r")){
        freopen("pqh.inp", "r", stdin);
        freopen("pqh.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t = 1; // cin >> t;
    while (t --) solve();
    return 0;
}

Compilation message

sparklers.cpp:18:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |           ^~~~
sparklers.cpp:18:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |                    ^~~~
sparklers.cpp:19:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |           ^~~~
sparklers.cpp:19:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |                    ^~~~
sparklers.cpp: In function 'void solve()':
sparklers.cpp:55:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 |         int mid = lo + hi >> 1;
      |                   ~~~^~~~
sparklers.cpp: In function 'int main()':
sparklers.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen("pqh.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen("pqh.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -