Submission #1092081

#TimeUsernameProblemLanguageResultExecution timeMemory
1092081thangdz2k7Sparklers (JOI17_sparklers)C++17
0 / 100
0 ms348 KiB
// 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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...