Submission #1153024

#TimeUsernameProblemLanguageResultExecution timeMemory
1153024AmirAli_H1Sparklers (JOI17_sparklers)C++20
50 / 100
16 ms1352 KiB
// In the name of Allah #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef complex<ld> cld; #define all(x) (x).begin(),(x).end() #define len(x) ((ll) (x).size()) #define F first #define S second #define pb push_back #define sep ' ' #define endl '\n' #define Mp make_pair #define kill(x) cout << x << '\n', exit(0) #define set_dec(x) cout << fixed << setprecision(x); #define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 1000 + 4; int n, k; ll t; ll A[maxn]; bool dp[maxn][maxn]; ll get_val(int i, int j, ll tx) { return (tx * (j - i + 1)) - (A[j] - A[i]); } bool ok(ll x) { ll tx = (t * x); if (tx >= A[n - 1]) return 1; for (int i = k; i >= 0; i--) { for (int j = k; j < n; j++) { if (i == k && j == k) { dp[i][j] = 1; } else { dp[i][j] = 0; if (i + 1 <= k) { if (get_val(i + 1, j, tx) >= (A[i + 1] - A[i])) dp[i][j] |= dp[i + 1][j]; } if (j - 1 >= k) { if (get_val(i, j - 1, tx) >= (A[j] - A[j - 1])) dp[i][j] |= dp[i][j - 1]; } } } } return dp[0][n - 1]; } void solve() { cin >> n >> k >> t; k--; t *= 2; for (int i = 0; i < n; i++) { cin >> A[i]; } ll l = -1, r = (A[n - 1] / t) + 2; while (r - l > 1) { ll mid = (l + r) / 2; if (ok(mid)) r = mid; else l = mid; } cout << r << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int T = 1; while (T--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...