# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1000627 |
2024-06-18T04:51:06 Z |
vjudge1 |
Safety (NOI18_safety) |
C++17 |
|
2000 ms |
7768 KB |
// #pragma optimize ("g",on)
// #pragma GCC optimize("inline")
// #pragma GCC optimize ("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC optimize ("03")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define file(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout);
#define adiyer(); ios_base::sync_with_stdio(0); cin.tie(0);
#define bitcount(n) __builtin_popcountll(n)
#define puts(x) cout << (x ? "YES\n" : "NO\n");
#define ent (i == n ? '\n' : ' ')
#define all(x) x.begin(), x.end()
#define md ((l + r) >> 1)
#define rv(v) ((v << 1) | 1)
#define lv(v) (v << 1)
#define rs(v) rv(v), md + 1, r
#define ls(v) lv(v), l, md
#define len(s) (int) s.size()
#define yes {cout << "YES\n"; return; }
#define no {cout << "no\n"; return; }
#define skip continue
#define pb push_back
#define S second
#define F first
// #define int long long
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef vector < ll > vll;
typedef pair < ll, ll > pll;
typedef vector < pair < ll, ll > > vpll;
typedef tree < ll, null_type, less < ll >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
const int N = 4e5 + 12;
const int K = 5000 + 12;
const int MAX = 2e5;
const int mod = 998244353;
const ll inf = 1e9 + 10;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
ll n, k;
ll a[N], dp[N], t[4 * N];
ll cmb(ll x, ll y){
return min(x, y);
}
void upd(ll k, ll x, ll v = 1, ll l = 1, ll r = N - 5){
if(l == r){
t[v] = x;
return;
}
if(k <= md) upd(k, x, (v << 1), l, md);
else upd(k, x, ((v << 1) | 1), md + 1, r);
t[v] = cmb(t[(v << 1)], t[((v << 1) | 1)]);
}
ll get(ll tl, ll tr, ll v = 1, ll l = 1, ll r = N - 5){
if(r < tl||tr < l) return inf;
if(tl <= l && r <= tr) return t[v];
return cmb(get(tl, tr, (v << 1), l, md), get(tl, tr, ((v << 1) | 1), md + 1, r));
}
void output(){
cin >> n >> k;
for(ll i = 1; i <= n; i++) cin >> a[i];
for(ll i = 1; i <= n; i++){
for(ll x = 0; x <= 5000; x++){
dp[x] = get(max(0ll, x - k), min(5000ll, x + k)) + abs(a[i] - x);
}
for(ll x = 0; x <= 5000; x++){
upd(x, dp[x]);
}
}
cout << get(0ll, 5000ll);
}
const bool cases = 0;
signed main(){
// file("disrupt");
adiyer();
int tt = 1;
if(cases) cin >> tt;
for(int i = 1; i <= tt; i++){
// cout << "Case " << i << ":\n";
output();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
4700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
4696 KB |
Output is correct |
2 |
Correct |
13 ms |
4716 KB |
Output is correct |
3 |
Correct |
12 ms |
4700 KB |
Output is correct |
4 |
Correct |
13 ms |
4700 KB |
Output is correct |
5 |
Incorrect |
13 ms |
4716 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
4700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2036 ms |
7768 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
4700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
4700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
4700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
4700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
4700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |