Datasets:

problem_id
stringlengths
6
6
buggy_code
stringlengths
8
526k
fixed_code
stringlengths
12
526k
labels
listlengths
0
15
buggy_submission_id
int64
1
1.54M
fixed_submission_id
int64
2
1.54M
user_id
stringlengths
10
10
language
stringclasses
9 values
p03161
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; int h[N]; for (int i = 0; i < N; i++) { cin >> h[i]; } vector<int> dp(N, INT_MAX); dp[0] = 1; for (int i = 1; i < N; i++) { for (int j = 1; i - j >= 0 && j <= K; j++) { dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j])); } } cout << dp.back(); }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; int h[N]; for (int i = 0; i < N; i++) { cin >> h[i]; } vector<int> dp(N, INT_MAX); dp[0] = 0; for (int i = 1; i < N; i++) { for (int j = 1; i - j >= 0 && j <= K; j++) { dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j])); } } cout << dp.back(); }
[ "literal.number.change", "assignment.value.change" ]
957,919
957,920
u931938233
cpp
p03161
#include <bits/stdc++.h> using namespace std; #define ALL(v) v.begin(), v.end() #define V vector #define P pair typedef long long ll; const int INT_INF = 1e9; const ll INF = 1LL << 30; const ll MOD = 1e9 + 7; int main() { ll n, k; cin >> n >> k; V<ll> h(n); for (int i = 0; i < n; i++) cin >> h[i]; V<ll> dp(n, INT_INF); dp[0] = 0; for (ll i = 0; i < n; i++) { for (ll j = i + 1; j < i + k; j++) { if (j < n) dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j])); } } cout << dp[n - 1] << "\n"; }
#include <bits/stdc++.h> using namespace std; #define ALL(v) v.begin(), v.end() #define V vector #define P pair typedef long long ll; const int INT_INF = 1e9; const ll INF = 1LL << 30; const ll MOD = 1e9 + 7; int main() { ll n, k; cin >> n >> k; V<ll> h(n); for (int i = 0; i < n; i++) cin >> h[i]; V<ll> dp(n, INT_INF); dp[0] = 0; for (ll i = 0; i < n; i++) { for (ll j = i + 1; j <= i + k; j++) { if (j < n) dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j])); } } cout << dp[n - 1] << "\n"; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
957,923
957,924
u701339058
cpp
p03161
// "It does not matter how slowly you go as long as you do not stop." - // Confucius #include <bits/stdc++.h> using namespace std; /* author : Roshan_Mehta motto : Time Management,Consistency,Patience!! */ #define int long long #ifdef Local_Debug #define debug(x) cout << #x << " " << x << " " #define debug1(a) cout << #a << " " << a << endl #define debug2(a, b) cout << #a << " " << a << " " << #b << " " << b << endl #define debug3(a, b, c) \ cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c \ << endl #define debug4(a, b, c, d) \ cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c \ << " " << #d << " " << d << endl void show(vector<int> a) { for (int i = 0; i < a.size(); i++) { cout << a[i] << " "; } cout << endl; } void show(vector<vector<int>> a) { for (int i = 0; i < a.size(); i++) { for (int j = 0; j < a[i].size(); j++) { cout << a[i][j] << " "; } cout << endl; } } void printTime(clock_t begin) { printf("%.3lf seconds\n", (double)(clock() - begin) / CLOCKS_PER_SEC); } #else #define debug(x) #define debug1(x) #define debug2(x, y) #define debug3(x, y, z) #define debug4(x, y, z, a) void show(vector<int> a) { return; } void show(vector<vector<int>> a) { return; } void printTime() { return; } #endif #define ll long long #define pb push_back #define fast() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define mp make_pair #define f first #define se second #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rsort(x) sort(x, greater<int>()) #define rall(x) rbegin(x), rend(x) // useful in sorting #define endl "\n" #define p0(a) cout << a << " " #define p1(a) cout << a << endl #define p2(a, b) cout << a << " " << b << endl #define p3(a, b, c) cout << a << " " << b << " " << c << endl #define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl #define gcd __gcd #define deci(n) fixed << setprecision(n) #define test() \ int test_case; \ cin >> test_case; \ while (test_case--) #define loop(i, a, n) for (int i = a; i < n; i++) typedef vector<int> vi; typedef vector<string> vs; typedef vector<ll> vl; typedef vector<vi> vvi; typedef pair<int, int> pi; typedef vector<pi> vpi; typedef pair<int, pi> tri; typedef pair<pi, int> rtri; typedef pair<ll, ll> pl; typedef pair<double, double> pd; typedef priority_queue<int, vector<int>, greater<int>> minpq; typedef priority_queue<int> pq; typedef unordered_map<int, int> umi; typedef map<int, int> mi; #define input(n, k) \ int n, k; \ cin >> n; \ cin >> k; \ vi arr(n, 0); \ loop(i, 0, n) { cin >> arr[i]; } const int MOD = 1e9 + 7; const int md = MOD; int Power(int n, int x) { int ans = 1; while (x > 0) { if (x & 1) ans = (ans * n) % md; n = (n * n) % md; x = x >> 1; } return ans; } vl fact, inv; void inverse(ll n) { if (n >= inv.size()) { ll size = inv.size(); size = size == 0 ? 1 : size; inv.resize(n + 1); inv[0] = 1; for (ll i = size; i <= n; i++) inv[i] = Power(fact[i], md - 2); } } void factorial(ll n) { if (n >= fact.size()) { ll size = fact.size(); size = size == 0 ? 1 : size; fact.resize(n + 1); fact[0] = 1; for (ll i = size; i <= n; i++) fact[i] = (fact[i - 1] * i) % md; } } ll ncr(ll n, ll r) { return (((fact[n] * inv[r]) % md) * inv[n - r]) % md; } vl SieveOfEratosthenes(int n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } vl ans; for (int p = 2; p <= n; p++) if (prime[p]) ans.pb(p); return ans; } ll NcR(int n, int r) { long long p = 1, k = 1; if (n - r < r) r = n - r; if (r != 0) { while (r) { p *= n; k *= r; long long m = gcd(p, k); p /= m; k /= m; n--; r--; } } else p = 1; return p; // cout << p << endl; } //********************THE END OF TEMPLATES*******************// void q1(); void q2(); void q3(); int32_t main() { clock_t begin = clock(); fast(); // test() // { // } q1(); // printf("%.3lf seconds,\n", (double) (clock() - begin) / CLOCKS_PER_SEC); return 0; } void q1() { int n, k; cin >> n >> k; vi arr(n); for (int i = 0; i < n; i++) { cin >> arr[i]; } vi dp(n); dp[0] = 0; for (int i = 1; i < k; i++) { dp[i] = abs(arr[0] - arr[i]); } // dp[1]=abs(arr[0]-arr[1]); for (int i = k; i < n; i++) { // dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i-2]-arr[i])); int ans = INT_MAX; for (int j = i - k; j < i; j++) { ans = min(ans, abs(arr[i] - arr[j]) + dp[j]); } dp[i] = ans; } cout << dp.back() << endl; show(dp); }
// "It does not matter how slowly you go as long as you do not stop." - // Confucius #include <bits/stdc++.h> using namespace std; /* author : Roshan_Mehta motto : Time Management,Consistency,Patience!! */ #define int long long #ifdef Local_Debug #define debug(x) cout << #x << " " << x << " " #define debug1(a) cout << #a << " " << a << endl #define debug2(a, b) cout << #a << " " << a << " " << #b << " " << b << endl #define debug3(a, b, c) \ cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c \ << endl #define debug4(a, b, c, d) \ cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c \ << " " << #d << " " << d << endl void show(vector<int> a) { for (int i = 0; i < a.size(); i++) { cout << a[i] << " "; } cout << endl; } void show(vector<vector<int>> a) { for (int i = 0; i < a.size(); i++) { for (int j = 0; j < a[i].size(); j++) { cout << a[i][j] << " "; } cout << endl; } } void printTime(clock_t begin) { printf("%.3lf seconds\n", (double)(clock() - begin) / CLOCKS_PER_SEC); } #else #define debug(x) #define debug1(x) #define debug2(x, y) #define debug3(x, y, z) #define debug4(x, y, z, a) void show(vector<int> a) { return; } void show(vector<vector<int>> a) { return; } void printTime() { return; } #endif #define ll long long #define pb push_back #define fast() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define mp make_pair #define f first #define se second #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rsort(x) sort(x, greater<int>()) #define rall(x) rbegin(x), rend(x) // useful in sorting #define endl "\n" #define p0(a) cout << a << " " #define p1(a) cout << a << endl #define p2(a, b) cout << a << " " << b << endl #define p3(a, b, c) cout << a << " " << b << " " << c << endl #define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl #define gcd __gcd #define deci(n) fixed << setprecision(n) #define test() \ int test_case; \ cin >> test_case; \ while (test_case--) #define loop(i, a, n) for (int i = a; i < n; i++) typedef vector<int> vi; typedef vector<string> vs; typedef vector<ll> vl; typedef vector<vi> vvi; typedef pair<int, int> pi; typedef vector<pi> vpi; typedef pair<int, pi> tri; typedef pair<pi, int> rtri; typedef pair<ll, ll> pl; typedef pair<double, double> pd; typedef priority_queue<int, vector<int>, greater<int>> minpq; typedef priority_queue<int> pq; typedef unordered_map<int, int> umi; typedef map<int, int> mi; #define input(n, k) \ int n, k; \ cin >> n; \ cin >> k; \ vi arr(n, 0); \ loop(i, 0, n) { cin >> arr[i]; } const int MOD = 1e9 + 7; const int md = MOD; int Power(int n, int x) { int ans = 1; while (x > 0) { if (x & 1) ans = (ans * n) % md; n = (n * n) % md; x = x >> 1; } return ans; } vl fact, inv; void inverse(ll n) { if (n >= inv.size()) { ll size = inv.size(); size = size == 0 ? 1 : size; inv.resize(n + 1); inv[0] = 1; for (ll i = size; i <= n; i++) inv[i] = Power(fact[i], md - 2); } } void factorial(ll n) { if (n >= fact.size()) { ll size = fact.size(); size = size == 0 ? 1 : size; fact.resize(n + 1); fact[0] = 1; for (ll i = size; i <= n; i++) fact[i] = (fact[i - 1] * i) % md; } } ll ncr(ll n, ll r) { return (((fact[n] * inv[r]) % md) * inv[n - r]) % md; } vl SieveOfEratosthenes(int n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } vl ans; for (int p = 2; p <= n; p++) if (prime[p]) ans.pb(p); return ans; } ll NcR(int n, int r) { long long p = 1, k = 1; if (n - r < r) r = n - r; if (r != 0) { while (r) { p *= n; k *= r; long long m = gcd(p, k); p /= m; k /= m; n--; r--; } } else p = 1; return p; // cout << p << endl; } //********************THE END OF TEMPLATES*******************// void q1(); void q2(); void q3(); int32_t main() { clock_t begin = clock(); fast(); // test() // { // } q1(); // printf("%.3lf seconds,\n", (double) (clock() - begin) / CLOCKS_PER_SEC); return 0; } void q1() { int n, k; cin >> n >> k; vi arr(n); for (int i = 0; i < n; i++) { cin >> arr[i]; } vi dp(n); dp[0] = 0; for (int i = 1; i < k and i < n; i++) { dp[i] = abs(arr[0] - arr[i]); } // dp[1]=abs(arr[0]-arr[1]); for (int i = k; i < n; i++) { // dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i-2]-arr[i])); int ans = INT_MAX; for (int j = i - k; j < i; j++) { ans = min(ans, abs(arr[i] - arr[j]) + dp[j]); } dp[i] = ans; } cout << dp.back() << endl; show(dp); }
[]
957,925
957,926
u276036901
cpp
p03161
#include <bits/stdc++.h> using namespace std; void solve(vector<int> &h, vector<int> &v, int k = 2) { int n = h.size(); for (int curr = 0; curr < n; curr++) { for (int j = curr + 1; j < n and j <= curr + k; j++) { int d1 = abs(h[curr] - h[curr + j]); v[j] = min(v[j], v[curr] + d1); } } } int main() { int n, k; cin >> n >> k; vector<int> h(n), v(n); for (int i = 0; i < n; i++) cin >> h[i]; v[0] = 0; for (int i = 1; i < n; i++) v[i] = INT_MAX; solve(h, v, k); cout << v[n - 1] << endl; }
#include <bits/stdc++.h> using namespace std; void solve(vector<int> &h, vector<int> &v, int k = 2) { int n = h.size(); for (int curr = 0; curr < n; curr++) { for (int j = curr + 1; j < n and j <= curr + k; j++) { int d1 = abs(h[curr] - h[j]); v[j] = min(v[j], v[curr] + d1); } } } int main() { int n, k; cin >> n >> k; vector<int> h(n), v(n); for (int i = 0; i < n; i++) cin >> h[i]; v[0] = 0; for (int i = 1; i < n; i++) v[i] = INT_MAX; solve(h, v, k); cout << v[n - 1] << endl; }
[ "expression.operation.binary.remove" ]
957,932
957,933
u772457931
cpp
p03161
#include <bits/stdc++.h> using namespace std; #define fi(n) for (int i = 0; i < n; i++) #define fj(n) for (int j = 0; j < n; j++) #define fr(n) for (int i = n - 1; i >= 0; i--) #define chlo(i, a, n) for (int i = a; i < n; i++) #define vi vector<int> #define vs vector<string> #define int long long int #define all(a) (a).begin(), (a).end() #define pb push_back #define setbits(x) __builtin_popcountll(x) #define zerbits(x) __builtinctzll(x) #define mod 1000000007 #define sz(x) (int)x.size() #define inf 1e18 #define W(x) \ int x; \ cin >> x; \ while (x--) #define ps(x, y) fixed << setprecision(y) << x #define mp make_pair #define INT_SIZE 32 #define pr pair<int, int> void aeh() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); #ifndef ONLINE_JUDGE freopen("aana.txt", "r", stdin); freopen("jj.txt", "w", stdout); #endif } int32_t main() { aeh(); int n, k; cin >> n >> k; vi a(n); fi(n) cin >> a[i]; int dp[n]{0}; // dp[i]would give the minimum cost to reach ith step dp[0] = 0; dp[1] = abs(a[1] - a[0]); for (int i = 2; i < min(n, k); i++) { int mnn = INT_MAX; for (int j = 0; j < i; j++) { mnn = min(mnn, dp[j] + abs(a[j] - a[i])); } dp[i] = mnn; } for (int i = k; i < n; i++) { int mn = INT_MAX; for (int j = i - k; j < i; j++) { mn = min(mn, dp[j] + abs(a[j] - a[i])); } dp[i] = mn; } cout << dp[n - 1] << endl; }
#include <bits/stdc++.h> using namespace std; #define fi(n) for (int i = 0; i < n; i++) #define fj(n) for (int j = 0; j < n; j++) #define fr(n) for (int i = n - 1; i >= 0; i--) #define chlo(i, a, n) for (int i = a; i < n; i++) #define vi vector<int> #define vs vector<string> #define int long long int #define all(a) (a).begin(), (a).end() #define pb push_back #define setbits(x) __builtin_popcountll(x) #define zerbits(x) __builtinctzll(x) #define mod 1000000007 #define sz(x) (int)x.size() #define inf 1e18 #define W(x) \ int x; \ cin >> x; \ while (x--) #define ps(x, y) fixed << setprecision(y) << x #define mp make_pair #define INT_SIZE 32 #define pr pair<int, int> void aeh() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); #ifndef ONLINE_JUDGE freopen("aana.txt", "r", stdin); freopen("jj.txt", "w", stdout); #endif } int32_t main() { int n, k; cin >> n >> k; vi a(n); fi(n) cin >> a[i]; int dp[n]{0}; // dp[i]would give the minimum cost to reach ith step dp[0] = 0; dp[1] = abs(a[1] - a[0]); for (int i = 2; i < min(n, k); i++) { int mnn = INT_MAX; for (int j = 0; j < i; j++) { mnn = min(mnn, dp[j] + abs(a[j] - a[i])); } dp[i] = mnn; } for (int i = k; i < n; i++) { int mn = INT_MAX; for (int j = i - k; j < i; j++) { mn = min(mn, dp[j] + abs(a[j] - a[i])); } dp[i] = mn; } cout << dp[n - 1] << endl; }
[ "call.remove" ]
957,936
957,937
u021830179
cpp
p03161
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define ff first #define ss second #define pb push_back #define mp make_pair #define pii pair<int, int> #define mk(arr, n, type) type *arr = new type[n]; #define vi vector<int> #define si set<int> #define usi unordered_set<int> #define mii map<int, int> #define umii unordered_map<int, int> #define pqmax priority_queue<int> #define pqmin priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define trailzrobits(x) __builtin_ctzll(x) #define leadzrobits(x) __builtin_clzll(x) #define paritybits(x) __builtin_parityll(x) #define gcd __gcd #define lcm(x, y) (x * y) / gcd(x, y) #define mod 1000000007 #define endl '\n' #define PI 3.14159265358979323846 #define inf 1e18 #define sp(x, y) fixed << setprecision(y) << x void __print(int x) { cout << x; } void __print(float x) { cout << x; } void __print(double x) { cout << x; } void __print(ld x) { cout << x; } void __print(char x) { cout << '\'' << x << '\''; } void __print(const char *x) { cout << '\"' << x << '\"'; } void __print(const string &x) { cout << '\"' << x << '\"'; } void __print(bool x) { cout << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}'; } template <typename T> void __print(const T &x) { int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}"; } void _print() { cout << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cout << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define dbg(x...) \ cout << "[" << #x << "]=["; \ _print(x) #else #define dbg(x...) #endif int power(int x, int y, int p = mod) { int res = 1; x %= p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int inv(int x, int p = mod) { return power(x, p - 2) % p; } const int N = 1e6 + 6; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) { int n, k; cin >> n >> k; mk(a, n + 1, int); for (int i = 1; i <= n; i++) cin >> a[i]; mk(dp, n + 1, int); fill(dp, dp + n + 1LL, 0); dp[2] = abs(a[2] - a[1]); for (int i = 3; i <= n; i++) { dp[i] = inf; for (int j = i - 1; j >= i - k; j--) { if (j >= 0) dp[i] = min(dp[i], abs(a[i] - a[j]) + dp[j]); } } cout << dp[n]; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define ff first #define ss second #define pb push_back #define mp make_pair #define pii pair<int, int> #define mk(arr, n, type) type *arr = new type[n]; #define vi vector<int> #define si set<int> #define usi unordered_set<int> #define mii map<int, int> #define umii unordered_map<int, int> #define pqmax priority_queue<int> #define pqmin priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define trailzrobits(x) __builtin_ctzll(x) #define leadzrobits(x) __builtin_clzll(x) #define paritybits(x) __builtin_parityll(x) #define gcd __gcd #define lcm(x, y) (x * y) / gcd(x, y) #define mod 1000000007 #define endl '\n' #define PI 3.14159265358979323846 #define inf 1e18 #define sp(x, y) fixed << setprecision(y) << x void __print(int x) { cout << x; } void __print(float x) { cout << x; } void __print(double x) { cout << x; } void __print(ld x) { cout << x; } void __print(char x) { cout << '\'' << x << '\''; } void __print(const char *x) { cout << '\"' << x << '\"'; } void __print(const string &x) { cout << '\"' << x << '\"'; } void __print(bool x) { cout << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}'; } template <typename T> void __print(const T &x) { int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}"; } void _print() { cout << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cout << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define dbg(x...) \ cout << "[" << #x << "]=["; \ _print(x) #else #define dbg(x...) #endif int power(int x, int y, int p = mod) { int res = 1; x %= p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int inv(int x, int p = mod) { return power(x, p - 2) % p; } const int N = 1e6 + 6; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) { int n, k; cin >> n >> k; mk(a, n + 1, int); for (int i = 1; i <= n; i++) cin >> a[i]; mk(dp, n + 1, int); fill(dp, dp + n + 1LL, 0); dp[2] = abs(a[2] - a[1]); for (int i = 3; i <= n; i++) { dp[i] = inf; for (int j = i - 1; j >= i - k; j--) { if (j >= 1) dp[i] = min(dp[i], abs(a[i] - a[j]) + dp[j]); } } cout << dp[n]; } return 0; }
[ "literal.number.change", "control_flow.branch.if.condition.change" ]
957,940
957,941
u612541354
cpp
p03161
#include <bits/stdc++.h> using namespace std; long long int dp[100005], ar[100005]; long long int solve(long long int i, long long int n, long long int m) { if (i == (n - 1)) return 0; if (i >= n) return 0; if (dp[i] != -1) return dp[i]; long long int mn = INT_MAX; for (long long int j = 1; j <= m; j++) { mn = min(mn, abs(ar[i + j] - ar[i]) + solve(i + j, n, m)); } return dp[i] = mn; } int main() { /*ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);*/ long long int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z; cin >> n >> m; for (i = 0; i < n; i++) { cin >> ar[i]; dp[i] = -1; } cout << solve(0, n, m) << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; long long int dp[100005], ar[100005]; long long int solve(long long int i, long long int n, long long int m) { if (i == (n - 1)) return 0; if (i >= n) return INT_MAX; if (dp[i] != -1) return dp[i]; long long int mn = INT_MAX; for (long long int j = 1; j <= m; j++) { mn = min(mn, abs(ar[i + j] - ar[i]) + solve(i + j, n, m)); } return dp[i] = mn; } int main() { /*ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);*/ long long int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z; cin >> n >> m; for (i = 0; i < n; i++) { cin >> ar[i]; dp[i] = -1; } cout << solve(0, n, m) << "\n"; return 0; }
[ "identifier.replace.add", "literal.replace.remove", "function.return_value.change" ]
957,948
957,949
u112451354
cpp
p03161
#include <bits/stdc++.h> #include <stdio.h> #include <stdlib.h> #define N 100005 #define K 200005 #define MOD 998244353 #define ll long long int using namespace std; int main() { int n, k; cin >> n >> k; int h[n]; for (int i = 0; i < n; i++) { cin >> h[i]; } vector<int> dp(n, 100000000); dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j <= i + k; j++) dp[j] = min(dp[i] + abs(h[j] - h[i]), dp[j]); } cout << dp[n - 1] << endl; return 0; }
#include <bits/stdc++.h> #include <stdio.h> #include <stdlib.h> #define N 100005 #define K 200005 #define MOD 998244353 #define ll long long int using namespace std; int main() { int n, k; cin >> n >> k; int h[n]; for (int i = 0; i < n; i++) { cin >> h[i]; } vector<int> dp(n, 1000000005); dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j <= i + k && j < n; j++) dp[j] = min(dp[i] + abs(h[j] - h[i]), dp[j]); } cout << dp[n - 1] << endl; return 0; }
[ "literal.number.change", "call.arguments.change", "control_flow.loop.for.condition.change" ]
957,954
957,955
u232473835
cpp
p03161
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define fi first #define se second #define pi pair<ll, ll> #define pii pair<ll, pi> #define pb push_back #define mk make_pair int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vector<int> height(n); for (int i = 1; i <= n; i++) { cin >> height[i]; } vector<int> dp(n + 2, 1e9); dp[1] = 0; for (int i = 2; i <= n; i++) { for (int j = 1; j <= k; j++) { if (i - j >= 1) { dp[i] = min(dp[i], dp[i - j] + abs(height[i] - height[i - j])); } } } cout << dp[n] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define fi first #define se second #define pi pair<ll, ll> #define pii pair<ll, pi> #define pb push_back #define mk make_pair int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vector<int> height(n + 1); for (int i = 1; i <= n; i++) { cin >> height[i]; } vector<int> dp(n + 1, 1e9); dp[1] = 0; for (int i = 2; i <= n; i++) { for (int j = 1; j <= k; j++) { if (i - j >= 1) { dp[i] = min(dp[i], dp[i - j] + abs(height[i] - height[i - j])); } } } cout << dp[n] << endl; }
[ "literal.number.change", "call.arguments.change", "expression.operation.binary.change" ]
957,969
957,968
u675040086
cpp
p03161
/* Author : Simanta Deb Turja */ #include <bits/stdc++.h> using namespace std; #define Professor using ll = long long; using i64 = unsigned long long; template <typename T> inline T Min(T a, T b, T c) { return min(a, min(b, c)); } template <typename T> inline T Min(T a, T b, T c, T d) { return min(a, min(b, min(c, d))); } template <typename T> inline T Max(T a, T b, T c) { return max(a, max(b, c)); } template <typename T> inline T Max(T a, T b, T c, T d) { return max(a, max(b, max(c, d))); } template <typename T> inline T Ceil(T a, T b) { return ((a % b == 0) ? (a / b) : (a / b + 1)); } template <typename T> inline T Floor(T a, T b) { return a / b; } template <typename T> inline T Power(T a, T p) { T res = 1, x = a; while (p) { if (p & 1) res = (res * x); x = (x * x); p >>= 1; } return res; } template <typename T> inline T BigMod(T a, T p, T M) { a %= M; T ret = 1; while (p) { if (p & 1) ret = (ret * a) % M; a = (a * a) % M; p = p >> 1; } return ret; } template <typename T> inline T InverseMod(T a, T M) { return BigMod(a, M - 2, M); } template <typename T> inline T gcd(T a, T b) { a = abs(a); b = abs(b); while (b) { a = a % b; swap(a, b); } return a; } template <typename T> inline T lcm(T x, T y) { return (((x) / gcd((x), (y))) * (y)); } #define endl '\n' #define eb emplace_back const int N = (int)4e5 + 10; const double EPS = 1e-7; const double PI = acos(-1.0); const ll LLINF = numeric_limits<ll>::max(); const int INF = numeric_limits<int>::max(); const ll MOD = (ll)1e9 + 7; template <typename T> bool cmp(const pair<T, T> &a, const pair<T, T> &b) { return a.first < b.first; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); auto Solve = [&]() { #ifdef __APPLE__ cout << "Running\n"; #endif int n, k; cin >> n >> k; vector<ll> h(n + 1, 0LL), dp(n + 1, LLINF); for (int i = 1; i <= n; ++i) { cin >> h[i]; } dp[1] = 0LL; for (int i = 2; i <= n; ++i) { for (int j = 1; j <= min(i, k); ++j) { dp[i] = min(dp[i], dp[i - j] + abs(h[i - j] - h[i])); } } cout << dp[n] << endl; }; Solve(); return 0; }
/* Author : Simanta Deb Turja */ #include <bits/stdc++.h> using namespace std; #define Professor using ll = long long; using i64 = unsigned long long; template <typename T> inline T Min(T a, T b, T c) { return min(a, min(b, c)); } template <typename T> inline T Min(T a, T b, T c, T d) { return min(a, min(b, min(c, d))); } template <typename T> inline T Max(T a, T b, T c) { return max(a, max(b, c)); } template <typename T> inline T Max(T a, T b, T c, T d) { return max(a, max(b, max(c, d))); } template <typename T> inline T Ceil(T a, T b) { return ((a % b == 0) ? (a / b) : (a / b + 1)); } template <typename T> inline T Floor(T a, T b) { return a / b; } template <typename T> inline T Power(T a, T p) { T res = 1, x = a; while (p) { if (p & 1) res = (res * x); x = (x * x); p >>= 1; } return res; } template <typename T> inline T BigMod(T a, T p, T M) { a %= M; T ret = 1; while (p) { if (p & 1) ret = (ret * a) % M; a = (a * a) % M; p = p >> 1; } return ret; } template <typename T> inline T InverseMod(T a, T M) { return BigMod(a, M - 2, M); } template <typename T> inline T gcd(T a, T b) { a = abs(a); b = abs(b); while (b) { a = a % b; swap(a, b); } return a; } template <typename T> inline T lcm(T x, T y) { return (((x) / gcd((x), (y))) * (y)); } #define endl '\n' #define eb emplace_back const int N = (int)4e5 + 10; const double EPS = 1e-7; const double PI = acos(-1.0); const ll LLINF = numeric_limits<ll>::max(); const int INF = numeric_limits<int>::max(); const ll MOD = (ll)1e9 + 7; template <typename T> bool cmp(const pair<T, T> &a, const pair<T, T> &b) { return a.first < b.first; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); auto Solve = [&]() { #ifdef __APPLE__ cout << "Running\n"; #endif int n, k; cin >> n >> k; vector<ll> h(n + 1, 0LL), dp(n + 1, (ll)1e10); for (int i = 1; i <= n; ++i) { cin >> h[i]; } dp[1] = 0LL; for (int i = 2; i <= n; ++i) { for (int j = 1; j <= min(i, k); ++j) { dp[i] = min(dp[i], dp[i - j] + abs(h[i - j] - h[i])); } } cout << dp[n] << endl; }; Solve(); return 0; }
[ "call.arguments.change" ]
957,970
957,971
u095814925
cpp
p03161
#include <bits/stdc++.h> using namespace std; #define ll long long #define p_q priority_queue #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) int main() { ll n, k; cin >> n >> k; vector<ll> h(n + 1, 0); for (ll i = 1; i <= n; i++) { cin >> h.at(i); } vector<ll> dp(n + 1, 1000000000); dp.at(0) = 0; dp.at(1) = 0; for (ll i = 2; i <= n; i++) { for (ll j = 1; j <= k; j++) { if (i - j < 0) break; dp.at(i) = min(dp.at(i), dp.at(i - j) + abs(h.at(i) - h.at(i - j))); } } cout << dp.at(n) << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define p_q priority_queue #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) int main() { ll n, k; cin >> n >> k; vector<ll> h(n + 1, 0); for (ll i = 1; i <= n; i++) { cin >> h.at(i); } vector<ll> dp(n + 1, 1000000000); dp.at(0) = 0; dp.at(1) = 0; for (ll i = 2; i <= n; i++) { for (ll j = 1; j <= k; j++) { if (i - j <= 0) break; dp.at(i) = min(dp.at(i), dp.at(i - j) + abs(h.at(i) - h.at(i - j))); } } cout << dp.at(n) << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
957,978
957,979
u830237447
cpp
p03161
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define vv(T) vector<vector<T>> using namespace std; using ll = long long; using vint = vector<int>; using vvint = vector<vector<int>>; using vll = vector<long long>; using vvll = vector<vector<long long>>; using vbool = vector<bool>; using vvbool = vector<vector<bool>>; using qint = queue<int>; using sint = stack<int>; using pii = pair<int, int>; int main() { int n, k; cin >> n >> k; vint h(n); rep(i, n) cin >> h[i]; vint cost(n, 0); for (int i = 1; i < n; i++) { int nextCost = 1e5; for (int j = 1; j <= k and j <= i; j++) { int tmp = abs(h[i] - h[i - j]) + cost[i - j]; nextCost = min(tmp, nextCost); } cost[i] = nextCost; } // for(auto x : cost) cout << x << endl; cout << cost.back() << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define vv(T) vector<vector<T>> using namespace std; using ll = long long; using vint = vector<int>; using vvint = vector<vector<int>>; using vll = vector<long long>; using vvll = vector<vector<long long>>; using vbool = vector<bool>; using vvbool = vector<vector<bool>>; using qint = queue<int>; using sint = stack<int>; using pii = pair<int, int>; int main() { int n, k; cin >> n >> k; vint h(n); rep(i, n) cin >> h[i]; vll cost(n, 0); for (int i = 1; i < n; i++) { ll nextCost = 1e9; for (int j = 1; j <= k and j <= i; j++) { ll tmp = abs(h[i] - h[i - j]) + cost[i - j]; nextCost = min(tmp, nextCost); } cost[i] = nextCost; } // for(auto x : cost) cout << x << endl; cout << cost.back() << endl; return 0; }
[ "variable_declaration.type.change", "literal.number.change", "variable_declaration.value.change" ]
957,984
957,985
u229213815
cpp
p03161
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <limits.h> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> ans(n); int k; cin >> k; vector<int> r(n); int e; cin >> e; r[0] = e; ans[0] = 0; for (int i = 1; i < k && i < n - 1; i++) { cin >> e; int add = INT_MAX; for (int j = 0; j < i; j++) { if (ans[j] + abs(e - r[j]) < add) { add = ans[j] + abs(e - r[j]); } } r[i] = e; ans[i] = add; } for (int i = k; i < n; i++) { cin >> e; r[i] = e; int add = INT_MAX; for (int j = i - k; j < i; j++) { if (ans[j] + abs(e - r[j]) < add) { add = ans[j] + abs(e - r[j]); } } ans[i] = add; } cout << ans[n - 1] << endl; return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <limits.h> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> ans(n); int k; cin >> k; vector<int> r(n); int e; cin >> e; r[0] = e; ans[0] = 0; for (int i = 1; i < k && i < n; i++) { cin >> e; int add = INT_MAX; for (int j = 0; j < i; j++) { if (ans[j] + abs(e - r[j]) < add) { add = ans[j] + abs(e - r[j]); } } r[i] = e; ans[i] = add; } for (int i = k; i < n; i++) { cin >> e; r[i] = e; int add = INT_MAX; for (int j = i - k; j < i; j++) { if (ans[j] + abs(e - r[j]) < add) { add = ans[j] + abs(e - r[j]); } } ans[i] = add; } cout << ans[n - 1] << endl; return 0; }
[ "control_flow.loop.for.condition.change", "expression.operation.binary.remove" ]
957,986
957,987
u274420084
cpp
p03161
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define MAX_N 1e5 + 10 #define inf 10000000 typedef long long ll; typedef vector<int> vi; typedef vector<bool> vbl; int main() { int n, k; cin >> n >> k; int h[n + 1], dp[n + 1]; for (int i = 1; i <= n; i++) { cin >> h[i]; dp[i] = -1; } dp[1] = 0; for (int i = 2; i <= n; i++) { for (int j = i - 1; j >= i - k && j >= 1; j--) { if (dp[i] == -1 || dp[i] < dp[j] + abs(h[i] - h[j])) { dp[i] = dp[j] + abs(h[i] - h[j]); } } } cout << dp[n] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define MAX_N 1e5 + 10 #define inf 10000000 typedef long long ll; typedef vector<int> vi; typedef vector<bool> vbl; int main() { int n, k; cin >> n >> k; int h[n + 1], dp[n + 1]; for (int i = 1; i <= n; i++) { cin >> h[i]; dp[i] = -1; } dp[1] = 0; for (int i = 2; i <= n; i++) { for (int j = i - 1; j >= i - k && j >= 1; j--) { if (dp[i] == -1 || dp[i] > dp[j] + abs(h[i] - h[j])) { dp[i] = dp[j] + abs(h[i] - h[j]); } } } cout << dp[n] << endl; return 0; }
[ "misc.opposites", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
957,989
957,990
u748761968
cpp
p03161
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <stdio.h> #include <string> #include <vector> #define f(i, n) for (int i = 0; i < n; i++) #define mod 10007 #define chk(d) cout << d << endl using namespace std; int main() { int n, m, k; cin >> n >> k; vector<int> v; f(i, n) { int a; cin >> a; v.push_back(a); } int dp[n]; f(i, n) dp[i] = mod; dp[0] = 0; dp[1] = abs(v[1] - v[0]); for (int i = 1; i < n - 1; i++) { for (int j = 1; j <= k && j <= i + 1; j++) dp[i + 1] = min(dp[i - j + 1] + abs(v[i - j + 1] - v[i + 1]), dp[i + 1]); // dp[i+1] = min(dp[i]+abs(v[i-1]-v[i+1])-abs(v[i]-v[i-1]),dp[i+1]); } // f(i,n)cout<<dp[i]<<" "; cout << dp[n - 1]; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <stdio.h> #include <string> #include <vector> #define f(i, n) for (int i = 0; i < n; i++) #define mod 1e9 + 7 #define chk(d) cout << d << endl using namespace std; int main() { int n, m, k; cin >> n >> k; vector<int> v; f(i, n) { int a; cin >> a; v.push_back(a); } int dp[n]; f(i, n) dp[i] = mod; dp[0] = 0; dp[1] = abs(v[1] - v[0]); for (int i = 1; i < n - 1; i++) { for (int j = 1; j <= k && j <= i + 1; j++) dp[i + 1] = min(dp[i - j + 1] + abs(v[i - j + 1] - v[i + 1]), dp[i + 1]); // dp[i+1] = min(dp[i]+abs(v[i-1]-v[i+1])-abs(v[i]-v[i-1]),dp[i+1]); } // f(i,n)cout<<dp[i]<<" "; cout << dp[n - 1]; }
[ "preprocessor.define.value.change", "literal.float.change" ]
957,993
957,994
u590683594
cpp
p03161
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <stdio.h> #include <string> #include <vector> #define f(i, n) for (int i = 0; i < n; i++) #define mod 100007 #define chk(d) cout << d << endl using namespace std; int main() { long int n, m, k; cin >> n >> k; vector<long int> v; f(i, n) { long int a; cin >> a; v.push_back(a); } long int dp[n + 3]; f(i, n) dp[i] = mod; dp[0] = 0; // dp[1] = abs(v[1]-v[0]); for (int i = 0; i < n; i++) { for (int j = 1; j <= k; j++) if (i + j < n) dp[i + j] = min(dp[i] + abs(v[i + j] - v[i]), dp[i + j]); // dp[i+1] = min(dp[i]+abs(v[i-1]-v[i+1])-abs(v[i]-v[i-1]),dp[i+1]); } // f(i,n)cout<<dp[i]<<" "; cout << dp[n - 1]; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <stdio.h> #include <string> #include <vector> #define f(i, n) for (int i = 0; i < n; i++) #define mod 1000000007 #define chk(d) cout << d << endl using namespace std; int main() { long int n, m, k; cin >> n >> k; vector<long int> v; f(i, n) { long int a; cin >> a; v.push_back(a); } long int dp[n + 3]; f(i, n) dp[i] = mod; dp[0] = 0; // dp[1] = abs(v[1]-v[0]); for (int i = 0; i < n; i++) { for (int j = 1; j <= k; j++) if (i + j < n) dp[i + j] = min(dp[i] + abs(v[i + j] - v[i]), dp[i + j]); // dp[i+1] = min(dp[i]+abs(v[i-1]-v[i+1])-abs(v[i]-v[i-1]),dp[i+1]); } // f(i,n)cout<<dp[i]<<" "; cout << dp[n - 1]; }
[ "preprocessor.define.value.change", "literal.integer.change" ]
958,000
958,002
u590683594
cpp
p03161
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <stdio.h> #include <string> #include <vector> #define f(i, n) for (int i = 0; i < n; i++) #define mod 10007 #define chk(d) cout << d << endl using namespace std; int main() { long int n, m, k; cin >> n >> k; vector<long int> v; f(i, n) { long int a; cin >> a; v.push_back(a); } long int dp[n + 3]; f(i, n) dp[i] = mod; dp[0] = 0; // dp[1] = abs(v[1]-v[0]); for (int i = 0; i < n; i++) { for (int j = 1; j <= k; j++) if (i + j < n) dp[i + j] = min(dp[i] + abs(v[i + j] - v[i]), dp[i + j]); // dp[i+1] = min(dp[i]+abs(v[i-1]-v[i+1])-abs(v[i]-v[i-1]),dp[i+1]); } // f(i,n)cout<<dp[i]<<" "; cout << dp[n - 1]; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <stdio.h> #include <string> #include <vector> #define f(i, n) for (int i = 0; i < n; i++) #define mod 1000000007 #define chk(d) cout << d << endl using namespace std; int main() { long int n, m, k; cin >> n >> k; vector<long int> v; f(i, n) { long int a; cin >> a; v.push_back(a); } long int dp[n + 3]; f(i, n) dp[i] = mod; dp[0] = 0; // dp[1] = abs(v[1]-v[0]); for (int i = 0; i < n; i++) { for (int j = 1; j <= k; j++) if (i + j < n) dp[i + j] = min(dp[i] + abs(v[i + j] - v[i]), dp[i + j]); // dp[i+1] = min(dp[i]+abs(v[i-1]-v[i+1])-abs(v[i]-v[i-1]),dp[i+1]); } // f(i,n)cout<<dp[i]<<" "; cout << dp[n - 1]; }
[ "preprocessor.define.value.change", "literal.integer.change" ]
958,001
958,002
u590683594
cpp
p03161
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <stdio.h> #include <string> #include <vector> #define f(i, n) for (int i = 0; i < n; i++) #define mod 10007 #define chk(d) cout << d << endl using namespace std; int main() { int n, m, k; cin >> n >> k; vector<int> v; f(i, n) { int a; cin >> a; v.push_back(a); } int dp[n + 3]; f(i, n) dp[i] = mod; dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = 1; j <= k; j++) if (i + j < n) dp[i + j] = min(dp[i] + abs(v[i + j] - v[i]), dp[i + j]); } cout << dp[n - 1]; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <stdio.h> #include <string> #include <vector> #define f(i, n) for (int i = 0; i < n; i++) #define mod 1000000007 #define chk(d) cout << d << endl using namespace std; int main() { long int n, m, k; cin >> n >> k; vector<long int> v; f(i, n) { long int a; cin >> a; v.push_back(a); } long int dp[n + 3]; f(i, n) dp[i] = mod; dp[0] = 0; // dp[1] = abs(v[1]-v[0]); for (int i = 0; i < n; i++) { for (int j = 1; j <= k; j++) if (i + j < n) dp[i + j] = min(dp[i] + abs(v[i + j] - v[i]), dp[i + j]); // dp[i+1] = min(dp[i]+abs(v[i-1]-v[i+1])-abs(v[i]-v[i-1]),dp[i+1]); } // f(i,n)cout<<dp[i]<<" "; cout << dp[n - 1]; }
[ "preprocessor.define.value.change", "literal.integer.change", "variable_declaration.type.widen.change" ]
958,003
958,002
u590683594
cpp
p03161
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { int n, k; cin >> n >> k; int a[n]; int dp[n]; for (int i = 0; i < n; i++) { cin >> a[i]; dp[i] = 100000; } dp[0] = 0; for (int i = 1; i < n; i++) { for (int j = 1; j <= k && j <= i; j++) { dp[i] = min(dp[i - j] + abs(a[i] - a[i - j]), dp[i]); } } cout << dp[n - 1] << endl; }
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { int n, k; cin >> n >> k; int a[n]; long long int dp[n]; for (int i = 0; i < n; i++) { cin >> a[i]; dp[i] = 1000000000; } dp[0] = 0; for (int i = 1; i < n; i++) { for (int j = 1; j <= k && j <= i; j++) { dp[i] = min(dp[i - j] + abs(a[i] - a[i - j]), dp[i]); } } cout << dp[n - 1] << endl; }
[ "literal.number.change", "assignment.value.change" ]
958,010
958,011
u842473278
cpp
p03161
#include <cstdlib> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const long long INF = 1LL << 60; // 入力 int N, k; long long h[100010]; // DP テーブル long long dp[100010]; int main() { int N, k; cin >> N >> k; for (int i = 0; i < N; ++i) cin >> h[i]; // 初期化 (最小化問題なので INF に初期化) for (int i = 0; i < 100010; ++i) dp[i] = INF; // 初期条件 dp[0] = 0; // ループ for (int i = 0; i < N; ++i) { for (int j = 1; j < k; j++) { chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j])); } } // 答え cout << dp[N - 1] << endl; }
#include <cstdlib> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const long long INF = 1LL << 60; // 入力 int N, k; long long h[100010]; // DP テーブル long long dp[100010]; int main() { int N, k; cin >> N >> k; for (int i = 0; i < N; ++i) cin >> h[i]; // 初期化 (最小化問題なので INF に初期化) for (int i = 0; i < 100010; ++i) dp[i] = INF; // 初期条件 dp[0] = 0; // ループ for (int i = 0; i < N; ++i) { for (int j = 1; j <= k; j++) { chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j])); } } // 答え cout << dp[N - 1] << endl; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
958,016
958,017
u298272335
cpp
p03161
#include <cstdlib> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const long long INF = 1LL << 60; // 入力 int N, k; long long h[100010]; // DP テーブル long long dp[100010]; int main() { int N, k; cin >> N >> k; for (int i = 0; i < N; ++i) cin >> h[i]; // 初期化 (最小化問題なので INF に初期化) for (int i = 0; i < 100010; ++i) dp[i] = INF; // 初期条件 dp[0] = 0; // ループ for (int i = 0; i < N; ++i) { for (int j = 0; j < k; j++) { chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j])); } } // 答え cout << dp[N - 1] << endl; }
#include <cstdlib> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const long long INF = 1LL << 60; // 入力 int N, k; long long h[100010]; // DP テーブル long long dp[100010]; int main() { int N, k; cin >> N >> k; for (int i = 0; i < N; ++i) cin >> h[i]; // 初期化 (最小化問題なので INF に初期化) for (int i = 0; i < 100010; ++i) dp[i] = INF; // 初期条件 dp[0] = 0; // ループ for (int i = 0; i < N; ++i) { for (int j = 1; j <= k; j++) { chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j])); } } // 答え cout << dp[N - 1] << endl; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
958,018
958,017
u298272335
cpp
p03161
#include <bits/stdc++.h> using namespace std; int main() { static long long int n, a[100010], b[100010], k; cin >> n >> k; fill(b, b + n, 100000); cin >> a[0]; b[0] = 0; for (long long int i = 1; i < n; i++) { cin >> a[i]; for (int j = 1; j <= k; j++) { if (i - j < 0) { break; } b[i] = min(b[i], b[i - j] + abs(a[i - j] - a[i])); } } cout << b[n - 1]; }
#include <bits/stdc++.h> using namespace std; int main() { static long long int n, a[1000010], b[1000010], k; cin >> n >> k; fill(b, b + n, 10000000000); cin >> a[0]; b[0] = 0; for (long long int i = 1; i < n; i++) { cin >> a[i]; for (long long int j = 1; j <= k; j++) { if (i - j < 0) { break; } b[i] = min(b[i], b[i - j] + abs(a[i - j] - a[i])); } } cout << b[n - 1]; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "call.arguments.change", "control_flow.loop.for.initializer.change" ]
958,022
958,020
u417303453
cpp
p03161
#define __USE_MINGW_ANSI_STDIO #define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> using namespace std; typedef long long ll; typedef long long ull; typedef pair<ll, ll> ii; #define all(v) ((v).begin()), ((v).end()) #define sz(v) ((int)((v).size())) #define endl "\n" #define fx(n) fixed << setprecision(n) #define mk make_pair void File() { #ifndef ONLINE_JUDGE freopen("output.txt", "w", stdout); freopen("input.txt", "r", stdin); #endif #ifdef ONLINE_JUDGE /*freopen("output.txt", "w", stdout); freopen("pyramid.in", "r", stdin);*/ #endif } void fast() { ios::sync_with_stdio(NULL); cout.tie(NULL); cin.tie(NULL); // File(); } const double pi = 2 * acos(0.0); const ll oo = 0x3f3f3f3f; const int MOD = 1e9 + 7; const int nn = 1e5 + 15; int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1}; int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1}; int n, k; ll arr[nn]; ll dp[nn]; int main() { fast(); cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; fill(dp, dp + nn, oo * oo); dp[0] = 0; dp[1] = abs(arr[1] - arr[0]); for (int i = 2; i < n; i++) { ll mn = oo * oo; for (int j = 1; j <= min({n, k}); j++) { mn = min(mn, dp[i - j] + abs(arr[i - j] - arr[i])); } dp[i] = mn; } cout << dp[n - 1] << endl; return 0; }
#define __USE_MINGW_ANSI_STDIO #define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> using namespace std; typedef long long ll; typedef long long ull; typedef pair<ll, ll> ii; #define all(v) ((v).begin()), ((v).end()) #define sz(v) ((int)((v).size())) #define endl "\n" #define fx(n) fixed << setprecision(n) #define mk make_pair void File() { #ifndef ONLINE_JUDGE freopen("output.txt", "w", stdout); freopen("input.txt", "r", stdin); #endif #ifdef ONLINE_JUDGE /*freopen("output.txt", "w", stdout); freopen("pyramid.in", "r", stdin);*/ #endif } void fast() { ios::sync_with_stdio(NULL); cout.tie(NULL); cin.tie(NULL); // File(); } const double pi = 2 * acos(0.0); const ll oo = 0x3f3f3f3f; const int MOD = 1e9 + 7; const int nn = 1e5 + 15; int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1}; int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1}; int n, k; ll arr[nn]; ll dp[nn]; int main() { fast(); cin >> n >> k; for (int i = 0; i < n; i++) cin >> arr[i]; fill(dp, dp + nn, oo * oo); dp[0] = 0; dp[1] = abs(arr[1] - arr[0]); for (int i = 2; i < n; i++) { ll mn = oo * oo; for (int j = 1; j <= min({i, k}); j++) { mn = min(mn, dp[i - j] + abs(arr[i - j] - arr[i])); } dp[i] = mn; } cout << dp[n - 1] << endl; return 0; }
[ "identifier.change", "control_flow.loop.for.condition.change", "call.arguments.change", "expression.operation.binary.change" ]
958,027
958,028
u292500766
cpp
p03161
// Created by the_solver... #include <bits/stdc++.h> using namespace std; // #define int long long #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } void solve() { int n, k; cin >> n >> k; int a[n], dp[n + 1]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i <= n; i++) dp[i] = 1e5; dp[0] = 0; // dp[1] = abs(a[1]-a[0]); // dp[2] = min((dp[1]+abs(a[2]-a[1])),abs(a[2]-a[0])); int i, j; for (int i = 1; i < n; i++) { for (i - k < 0 ? j = 0 : j = i - k; j < i; j++) { dp[i] = min((dp[j] + abs(a[j] - a[i])), dp[i]); } } cout << dp[n - 1] << endl; } int32_t main() { // fastio(); // int t;cin>>t; // while(t--) solve(); return 0; }
// Created by the_solver... #include <bits/stdc++.h> using namespace std; // #define int long long #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } void solve() { int n, k; cin >> n >> k; int a[n], dp[n + 1]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i <= n; i++) dp[i] = mod; dp[0] = 0; // dp[1] = abs(a[1]-a[0]); // dp[2] = min((dp[1]+abs(a[2]-a[1])),abs(a[2]-a[0])); int i, j; for (int i = 1; i < n; i++) { for (i - k < 0 ? j = 0 : j = i - k; j < i; j++) { // dont know why j<=i got accepted and j<i not!!! dp[i] = min((dp[j] + abs(a[j] - a[i])), dp[i]); } } cout << dp[n - 1] << endl; } int32_t main() { // fastio(); // int t;cin>>t; // while(t--) solve(); return 0; }
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove" ]
958,029
958,030
u419699727
cpp
p03161
// Created by the_solver... #include <bits/stdc++.h> using namespace std; // #define int long long #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } void solve() { int n, k; cin >> n >> k; int a[n], dp[n + 1]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i <= n; i++) dp[i] = 1e5; dp[0] = 0; // dp[1] = abs(a[1]-a[0]); // dp[2] = min((dp[1]+abs(a[2]-a[1])),abs(a[2]-a[0])); int i, j; for (int i = 1; i < n; i++) { for (i - k < 0 ? j = 0 : j = i - k; j < i; j++) { dp[i] = min((dp[j] + abs(a[j] - a[i])), dp[i]); } } cout << dp[n - 1] << endl; } int32_t main() { // fastio(); // int t;cin>>t; // while(t--) solve(); return 0; }
// Created by the_solver... #include <bits/stdc++.h> using namespace std; // #define int long long #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } void solve() { int n, k; cin >> n >> k; int a[n], dp[n + 1]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i <= n; i++) dp[i] = mod; dp[0] = 0; // dp[1] = abs(a[1]-a[0]); // dp[2] = min((dp[1]+abs(a[2]-a[1])),abs(a[2]-a[0])); int i, j; for (int i = 1; i < n; i++) { for (i - k < 0 ? j = 0 : j = i - k; j <= i; j++) { dp[i] = min((dp[j] + abs(a[j] - a[i])), dp[i]); } } cout << dp[n - 1] << endl; } int32_t main() { // fastio(); // int t;cin>>t; // while(t--) solve(); return 0; }
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
958,029
958,031
u419699727
cpp
p03161
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> h(N); vector<int> cost(N); for (int i = 0; i < N; i++) { cin >> h.at(i); cost.at(i) = 1000; } cost.at(0) = 0; if (N > K) { for (int i = 1; i < K; i++) { for (int j = i; j > 0; j--) { cost.at(i) = min((cost.at(i - j) + abs(h.at(i) - h.at(i - j))), cost.at(i)); } } for (int i = K; i < N; i++) { for (int j = K; j > 0; j--) { cost.at(i) = min((cost.at(i - j) + abs(h.at(i) - h.at(i - j))), cost.at(i)); } } } else { for (int i = 1; i < N; i++) { for (int j = i; j > 0; j--) { cost.at(i) = min((cost.at(i - j) + abs(h.at(i) - h.at(i - j))), cost.at(i)); } } } cout << cost.at(N - 1) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> h(N); vector<int> cost(N); for (int i = 0; i < N; i++) { cin >> h.at(i); cost.at(i) = 10000000000; } cost.at(0) = 0; if (N > K) { for (int i = 1; i < K; i++) { for (int j = i; j > 0; j--) { cost.at(i) = min((cost.at(i - j) + abs(h.at(i) - h.at(i - j))), cost.at(i)); } } for (int i = K; i < N; i++) { for (int j = K; j > 0; j--) { cost.at(i) = min((cost.at(i - j) + abs(h.at(i) - h.at(i - j))), cost.at(i)); } } } else { for (int i = 1; i < N; i++) { for (int j = i; j > 0; j--) { cost.at(i) = min((cost.at(i - j) + abs(h.at(i) - h.at(i - j))), cost.at(i)); } } } cout << cost.at(N - 1) << endl; }
[ "literal.number.change", "assignment.value.change" ]
958,032
958,033
u507351098
cpp
p03161
#include <bits/stdc++.h> using namespace std; #define li long long int int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); int n, i, x, k; cin >> n >> k; li dp[n + 1] = {0}, h[n + 1] = {0}; for (i = 1; i <= n; i++) { cin >> h[i]; } dp[0] = dp[1] = 0; dp[2] = abs(h[2] - h[1]); for (i = 3; i <= n; i++) { dp[i] = INT_MAX; for (int j = 1; j <= k; j++) { if (i - j >= 0) dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j])); } } cout << dp[n]; return 0; }
#include <bits/stdc++.h> using namespace std; #define li long long int int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); li n, i, x, k; cin >> n >> k; li dp[n + 1] = {0}, h[n + 1] = {0}; for (i = 1; i <= n; i++) { cin >> h[i]; } dp[0] = dp[1] = 0; dp[2] = abs(h[2] - h[1]); for (i = 2; i <= n; i++) { dp[i] = INT_MAX; for (li j = 1; j <= k; j++) { if (i - j > 0) dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j])); } } cout << dp[n]; return 0; }
[ "variable_declaration.type.change", "literal.number.change", "assignment.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
958,039
958,040
u774966777
cpp
p03161
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k; cin >> n >> k; int a[n + 1], dp[n + 1]; for (i = 1; i <= n; i++) cin >> a[i]; dp[1] = 0; dp[2] = abs(a[2] - a[1]); for (i = 3; i <= n; i++) { int mn = 1e09; for (j = i - 1; j >= max(0, i - k); j--) { mn = min(mn, abs(a[j] - a[i]) + dp[j]); } dp[i] = mn; } cout << dp[n]; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, k; cin >> n >> k; int a[n + 1], dp[n + 1]; for (i = 1; i <= n; i++) cin >> a[i]; dp[1] = 0; dp[2] = abs(a[2] - a[1]); for (i = 3; i <= n; i++) { int mn = 1e09; for (j = i - 1; j >= max(1, i - k); j--) { mn = min(mn, abs(a[j] - a[i]) + dp[j]); } dp[i] = mn; } cout << dp[n]; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "call.arguments.change", "expression.operation.binary.change" ]
958,042
958,043
u629369127
cpp
p03161
#include <iostream> #include <vector> using namespace std; #define ll long long ll frog1(ll d[], ll b) { // if b==0 no steps to jump if (b <= 1) return 0; // he may jump 1 or 2 steps // with minimum cosst int p = abs(d[b - 1] - d[b - 2]) + frog1(d, b - 1); int r = (b <= 2) ? 10000 : abs(d[b - 1] - d[b - 3]) + frog1(d, b - 2); return min(p, r); } ll frog(ll d[], ll b, ll k) { // if b==0 no steps to jump vector<ll> dp(b + 1); // he may jump 1 or 2 steps // with minimum cost dp[1] = 0; for (ll i = 2; i <= b; i++) { dp[i] = 1000000000; for (ll j = i - 1; j >= 1 && (i - j) <= k; j--) { dp[i] = min(dp[i], abs(d[i] - d[j]) + dp[j]); // cout<<dp[i]<<" "; } // cout<<dp[i]<<" "; } return dp[b]; } int main() { ll b, l; cin >> b >> l; ll d[b]; for (ll i = 1; i <= b; i++) cin >> d[i]; cout << frog(d, b, l) << endl; return 0; }
#include <iostream> #include <vector> using namespace std; #define ll long long ll frog1(ll d[], ll b) { // if b==0 no steps to jump if (b <= 1) return 0; // he may jump 1 or 2 steps // with minimum cosst int p = abs(d[b - 1] - d[b - 2]) + frog1(d, b - 1); int r = (b <= 2) ? 10000 : abs(d[b - 1] - d[b - 3]) + frog1(d, b - 2); return min(p, r); } ll frog(ll d[], ll b, ll k) { // if b==0 no steps to jump vector<ll> dp(b + 1); // he may jump 1 or 2 steps // with minimum cost dp[1] = 0; for (ll i = 2; i <= b; i++) { dp[i] = 1000000000; for (ll j = i - 1; j >= 1 && (i - j) <= k; j--) { dp[i] = min(dp[i], abs(d[i] - d[j]) + dp[j]); // cout<<dp[i]<<" "; } // cout<<dp[i]<<" "; } return dp[b]; } int main() { ll b, l; cin >> b >> l; ll d[b + 1]; for (ll i = 1; i <= b; i++) cin >> d[i]; cout << frog(d, b, l) << endl; return 0; }
[ "variable_declaration.array_dimensions.change", "expression.operation.binary.add" ]
958,048
958,049
u278997427
cpp
p03161
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define MOD 1000000007 #define mi 100000 int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int a[n], c[n]; for (int i = 0; i < n; i++) cin >> a[i]; c[0] = 0; for (int i = 1; i < n; i++) { ull min = mi; for (int j = i - 1; j >= 0 && j >= i - k; j--) { if (abs(a[j] - a[i]) + c[j] < min) min = abs(a[j] - a[i]) + c[j]; } c[i] = min; } cout << c[n - 1]; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define MOD 1000000007 #define mi 1000000000 int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int a[n], c[n]; for (int i = 0; i < n; i++) cin >> a[i]; c[0] = 0; for (int i = 1; i < n; i++) { ull min = mi; for (int j = i - 1; j >= 0 && j >= i - k; j--) { if (abs(a[j] - a[i]) + c[j] < min) min = abs(a[j] - a[i]) + c[j]; } c[i] = min; } cout << c[n - 1]; return 0; }
[ "preprocessor.define.value.change", "literal.integer.change" ]
958,052
958,053
u101591379
cpp
p03161
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int arr[n]; int i, j; int dp[n]; for (i = 0; i < n; i++) { dp[i] = 0; cin >> arr[i]; } for (i = 1; i < n; i++) { dp[i] = INT_MAX; for (j = i - 1; j >= i - k; j--) { int a1 = abs(arr[i] - arr[j]) + dp[j]; dp[i] = min(dp[i], a1); } } cout << dp[n - 1]; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int arr[n]; int i, j; int dp[n]; for (i = 0; i < n; i++) { dp[i] = 0; cin >> arr[i]; } for (i = 1; i < n; i++) { dp[i] = INT_MAX; for (j = i - 1; j >= i - k && j >= 0; j--) { int a1 = abs(arr[i] - arr[j]) + dp[j]; dp[i] = min(dp[i], a1); } } cout << dp[n - 1]; return 0; }
[ "control_flow.loop.for.condition.change" ]
958,056
958,057
u610655627
cpp
p03161
#include <bits/stdc++.h> #define int long long using namespace std; int32_t main() { int n, k; cin >> n >> k; int a[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } int dp[n + 1]; dp[1] = 0; for (int i = 2; i <= k && i <= n; i++) { dp[i] = dp[1] = abs(a[i] - a[1]); } for (int i = k + 1; i <= n; i++) { dp[i] = LONG_LONG_MAX; for (int j = k; j >= 1; j--) { dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j])); } } cout << dp[n] << endl; return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; int32_t main() { int n, k; cin >> n >> k; int a[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } int dp[n + 1]; dp[1] = 0; for (int i = 2; i <= k && i <= n; i++) { dp[i] = dp[1] + abs(a[i] - a[1]); } for (int i = k + 1; i <= n; i++) { dp[i] = LONG_LONG_MAX; for (int j = k; j >= 1; j--) { dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j])); } } cout << dp[n] << endl; return 0; }
[ "assignment.value.change" ]
958,062
958,063
u748516141
cpp
p03161
#include <bits/stdc++.h> using namespace std; #define ll long long int #define MOD 1000000007 int main() { ll n, i, j, cnt = 1, k = 1, w1, w2, w3, t, a, b, c, d, e, s, r; /* freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);*/ cin >> n >> k; ll h[n]; ll dp[n]; for (i = 0; i < n; i++) { dp[i] = 100000; } for (i = 0; i < n; i++) { cin >> h[i]; } dp[0] = 0; dp[1] = abs(h[1] - h[0]); for (i = 0; i < n; i++) { for (j = i + 1; j <= i + k && j < n; j++) { dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i])); } } cout << dp[n - 1]; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define MOD 1000000007 int main() { ll n, i, j, cnt = 1, k = 1, w1, w2, w3, t, a, b, c, d, e, s, r; /* freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);*/ cin >> n >> k; ll h[n]; ll dp[n]; for (i = 0; i < n; i++) { dp[i] = 1e9; } for (i = 0; i < n; i++) { cin >> h[i]; } dp[0] = 0; dp[1] = abs(h[1] - h[0]); for (i = 0; i < n; i++) { for (j = i + 1; j <= i + k && j < n; j++) { dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i])); } } cout << dp[n - 1]; return 0; }
[ "literal.number.change", "assignment.value.change" ]
958,066
958,067
u097163034
cpp
p03161
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <sstream> #include <string> #include <typeinfo> #include <vector> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> h(N); for (int i = 0; i < N; i++) { cin >> h[i]; } vector<long long int> dp(N, 0); dp[0] = 0; dp[1] = abs(h[0] - h[1]); for (int i = 1; i < N - 1; i++) { int min = 100000; for (int j = 0; j < K; j++) { if (i - j >= 0 && abs(h[i - j] - h[i + 1]) + dp[i - j] < min) { min = abs(h[i - j] - h[i + 1]) + dp[i - j]; } } dp[i + 1] = min; } cout << dp[N - 1] << endl; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <sstream> #include <string> #include <typeinfo> #include <vector> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> h(N); for (int i = 0; i < N; i++) { cin >> h[i]; } vector<long long int> dp(N, 0); dp[0] = 0; dp[1] = abs(h[0] - h[1]); for (int i = 1; i < N - 1; i++) { long long int min = 1000000000; for (int j = 0; j < K; j++) { if (i - j >= 0 && abs(h[i - j] - h[i + 1]) + dp[i - j] < min) { min = abs(h[i - j] - h[i + 1]) + dp[i - j]; } } dp[i + 1] = min; } cout << dp[N - 1] << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
958,076
958,077
u326660998
cpp
p03161
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <sstream> #include <string> #include <typeinfo> #include <vector> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> h(N); for (int i = 0; i < N; i++) { cin >> h[i]; } vector<int> dp(N, 0); dp[0] = 0; dp[1] = abs(h[0] - h[1]); for (int i = 1; i < N - 1; i++) { int min = 100000; for (int j = 0; j < K; j++) { if (i - j >= 0 && abs(h[i - j] - h[i + 1]) + dp[i - j] < min) { min = abs(h[i - j] - h[i + 1]) + dp[i - j]; } } dp[i + 1] = min; } cout << dp[N - 1] << endl; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <sstream> #include <string> #include <typeinfo> #include <vector> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> h(N); for (int i = 0; i < N; i++) { cin >> h[i]; } vector<long long int> dp(N, 0); dp[0] = 0; dp[1] = abs(h[0] - h[1]); for (int i = 1; i < N - 1; i++) { long long int min = 1000000000; for (int j = 0; j < K; j++) { if (i - j >= 0 && abs(h[i - j] - h[i + 1]) + dp[i - j] < min) { min = abs(h[i - j] - h[i + 1]) + dp[i - j]; } } dp[i + 1] = min; } cout << dp[N - 1] << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
958,078
958,077
u326660998
cpp
p03161
#include <climits> #include <iostream> #include <vector> using namespace std; int frog(vector<int> h, int n, int k) { vector<int> dp(n + 1); dp[1] = 0; for (int i = 2; i <= n; i++) { int m = INT_MAX; for (int j = 0; j < k; j++) { if (i - j >= 1) { int op = abs(h[i] - h[i - j]) + dp[i - j]; m = min(op, m); } } dp[i] = m; } return dp[n]; } int main() { int n; cin >> n; int k; cin >> k; vector<int> h(n + 1); for (int i = 1; i <= n; ++i) { cin >> h[i]; } int f = frog(h, n, k); cout << f << endl; }
#include <climits> #include <iostream> #include <vector> using namespace std; int frog(vector<int> h, int n, int k) { vector<int> dp(n + 1); dp[1] = 0; for (int i = 2; i <= n; i++) { int m = INT_MAX; for (int j = 1; j < k + 1; j++) { if (i - j >= 1) { int op = abs(h[i] - h[i - j]) + dp[i - j]; m = min(op, m); } } dp[i] = m; } return dp[n]; } int main() { int n; cin >> n; int k; cin >> k; vector<int> h(n + 1); for (int i = 1; i <= n; ++i) { cin >> h[i]; } int f = frog(h, n, k); cout << f << endl; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "control_flow.loop.for.condition.change", "misc.off_by_one" ]
958,086
958,087
u831213405
cpp
p03161
#include <climits> #include <iostream> #include <vector> using namespace std; int frog(vector<int> h, int n, int k) { vector<int> dp(n + 1); dp[1] = 0; for (int i = 2; i <= n; i++) { int m = INT_MAX; for (int j = 0; j < k; j++) { if (i - k >= 1) { int op = abs(h[i] - h[i - j]) + dp[i - j]; m = min(op, m); } } dp[i] = m; } return dp[n]; } int main() { int n; cin >> n; int k; cin >> k; vector<int> h(n + 1); for (int i = 1; i <= n; ++i) { cin >> h[i]; } int f = frog(h, n, k); cout << f << endl; }
#include <climits> #include <iostream> #include <vector> using namespace std; int frog(vector<int> h, int n, int k) { vector<int> dp(n + 1); dp[1] = 0; for (int i = 2; i <= n; i++) { int m = INT_MAX; for (int j = 1; j < k + 1; j++) { if (i - j >= 1) { int op = abs(h[i] - h[i - j]) + dp[i - j]; m = min(op, m); } } dp[i] = m; } return dp[n]; } int main() { int n; cin >> n; int k; cin >> k; vector<int> h(n + 1); for (int i = 1; i <= n; ++i) { cin >> h[i]; } int f = frog(h, n, k); cout << f << endl; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "control_flow.loop.for.condition.change", "misc.off_by_one", "identifier.change", "control_flow.branch.if.condition.change" ]
958,088
958,087
u831213405
cpp
p03161
#include <climits> #include <iostream> #include <vector> using namespace std; int frog(vector<int> h, int n, int k) { vector<int> dp(n + 1); dp[1] = 0; for (int i = 2; i <= n; i++) { int m = INT_MAX; for (int j = 0; j < k; j++) { if (i - k >= 1) { int op = abs(h[i] - h[i - k]) + dp[i - k]; m = min(op, m); } } dp[i] = m; } return dp[n]; } int main() { int n; cin >> n; int k; cin >> k; vector<int> h(n + 1); for (int i = 1; i <= n; ++i) { cin >> h[i]; } int f = frog(h, n, k); cout << f << endl; }
#include <climits> #include <iostream> #include <vector> using namespace std; int frog(vector<int> h, int n, int k) { vector<int> dp(n + 1); dp[1] = 0; for (int i = 2; i <= n; i++) { int m = INT_MAX; for (int j = 1; j < k + 1; j++) { if (i - j >= 1) { int op = abs(h[i] - h[i - j]) + dp[i - j]; m = min(op, m); } } dp[i] = m; } return dp[n]; } int main() { int n; cin >> n; int k; cin >> k; vector<int> h(n + 1); for (int i = 1; i <= n; ++i) { cin >> h[i]; } int f = frog(h, n, k); cout << f << endl; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "control_flow.loop.for.condition.change", "misc.off_by_one", "identifier.change", "control_flow.branch.if.condition.change", "call.arguments.change", "expression.opera...
958,089
958,087
u831213405
cpp
p03161
#include <bits/stdc++.h> using namespace std; int main() { // your code goes here ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n; cin >> k; vector<int> v(n); vector<int> arr(n); // stores minimum energy to reach ith pillar arr[0] = 0; for (int i = 0; i < n; i++) { cin >> v[i]; arr[i] = 500; } arr[0] = 0; // cout<<arr[0]; // arr[1]=abs(v[0]-v[1]); // cout<<arr[1]; for (int i = 0; i < n; i++) { for (int j = 1; j <= k; j++) { if (i + j < n) { // cout<<"ok"; // cout<<arr[i+j]<<" "<<(arr[i]+abs(v[i+j]-v[i])); arr[i + j] = min(arr[i + j], (arr[i] + abs(v[i + j] - v[i]))); } } // cout<<arr[i]; } cout << arr[n - 1]; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { // your code goes here ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n; cin >> k; vector<int> v(n); vector<int> arr(n); // stores minimum energy to reach ith pillar arr[0] = 0; for (int i = 0; i < n; i++) { cin >> v[i]; arr[i] = INT_MAX; } arr[0] = 0; // cout<<arr[0]; // arr[1]=abs(v[0]-v[1]); // cout<<arr[1]; for (int i = 0; i < n; i++) { for (int j = 1; j <= k; j++) { if (i + j < n) { // cout<<"ok"; // cout<<arr[i+j]<<" "<<(arr[i]+abs(v[i+j]-v[i])); arr[i + j] = min(arr[i + j], (arr[i] + abs(v[i + j] - v[i]))); } } // cout<<arr[i]; } cout << arr[n - 1]; return 0; }
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove" ]
958,090
958,091
u831340327
cpp
p03161
#include <bits/stdc++.h> #define f(i, a, b) for (ll i = a; i < b; i++) #define af(i, a, b) for (ll i = a; i >= b; i--) #define rep(i, a, b, k) for (ll i = a; i < b; i += k) #define arep(i, a, b, k) for (ll i = a; i >= b; i -= k) #define ones(x) (ll) __builtin_popcount(x) #define fs first #define sc second #define pb push_back #define po pop_back #define mp make_pair #define sz(a) (ll) a.size() #define all(a) a.begin(), a.end() #define sor(a) sort(a.begin(), a.end()) #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define ller \ ios::sync_with_stdio(false); \ cin.tsie(nullptr); \ cout.tie(nullptr) #define PI 3.1415926535 using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> ii; typedef vector<ll> vi; typedef vector<ii> vii; const ll MAX = 1e5 + 7; const ll inf = 1e18 + 5; ll n, k, h[MAX]; ll dp[MAX]; ll DP(ll u) { ll &ans = dp[u]; if (u == 1) return 0; if (ans != inf) return ans; f(i, u - k, u) { if (u > k) continue; ans = min(ans, DP(i) + abs(h[u] - h[i])); } return ans; } int main() { fastio; cin >> n >> k; f(i, 0, n + 3) dp[i] = inf; f(i, 1, n + 1) { cin >> h[i]; } cout << DP(n) << endl; return 0; }
#include <bits/stdc++.h> #define f(i, a, b) for (ll i = a; i < b; i++) #define af(i, a, b) for (ll i = a; i >= b; i--) #define rep(i, a, b, k) for (ll i = a; i < b; i += k) #define arep(i, a, b, k) for (ll i = a; i >= b; i -= k) #define ones(x) (ll) __builtin_popcount(x) #define fs first #define sc second #define pb push_back #define po pop_back #define mp make_pair #define sz(a) (ll) a.size() #define all(a) a.begin(), a.end() #define sor(a) sort(a.begin(), a.end()) #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define ller \ ios::sync_with_stdio(false); \ cin.tsie(nullptr); \ cout.tie(nullptr) #define PI 3.1415926535 using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> ii; typedef vector<ll> vi; typedef vector<ii> vii; const ll MAX = 1e5 + 7; const ll inf = 1e18 + 5; ll n, k, h[MAX]; ll dp[MAX]; ll DP(ll u) { ll &ans = dp[u]; if (u == 1) return 0; if (ans != inf) return ans; f(i, u - k, u) { if (i <= 0) continue; ans = min(ans, DP(i) + abs(h[u] - h[i])); } return ans; } int main() { fastio; cin >> n >> k; f(i, 0, n + 3) dp[i] = inf; f(i, 1, n + 1) { cin >> h[i]; } cout << DP(n) << endl; return 0; }
[]
958,094
958,095
u896379188
cpp
p03161
// THIS IS MY NINJA WAY #include <algorithm> #include <bits/stdc++.h> #include <ctime> #include <ext/pb_ds/assoc_container.hpp> #include <vector> #define str string #define dbl double #define ll long long int #define ull unsigned long long int #define vl vector<ll> #define vs vector<str> #define pll pair<ll, ll> #define vll vector<pll> #define sl set<ll> #define pb push_back #define mp make_pair #define ub upper_bound #define lb lower_bound #define BS binary_search #define ff first #define ss second #define fast \ ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); \ srand(time(NULL)); #define fr(i, a, b) for (long long i = a; i < b; i++) #define nfr(i, a, b) for (long long i = a; i <= b; i++) #define psl pair<str, ll> #define pls pair<ll, str> #define pss pair<str, str> #define lcm(a, b) (a * b) / __gcd(a, b) #define ALL(a) a.begin(), a.end() #define stl stack<ll> #define coml complex<ll> #define INF 0x3f3f3f3f3f3f3f3f #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define read(v, n) fr(i, 0, n) cin >> v[i]; #define print(x) \ fr(i, 0, x.size()) cout << x[i] << " "; \ cout << "\n"; const ll MOD = 1e9 + 7; const ll N = 2e5 + 5; using namespace std; using namespace __gnu_pbds; void solve() { ll n, k; cin >> n >> k; vl v(n); read(v, n); vl dp(n, INF); dp[0] = 0, dp[1] = abs(v[0] - v[1]); // fr(i,2,k){ // fr(j,1,k+1){ // if(i-j>=0)dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j])); // } // } fr(i, 2, n) { fr(j, 1, k + 1) { if (i - j >= 0) dp[i] = min(dp[i], dp[i - j] + abs(v[i] - v[i - j])); } } print(dp); cout << dp[n - 1]; } int main() { fast ll t; t = 1; // cin>>t; while (t--) { solve(); } return 0; }
// THIS IS MY NINJA WAY #include <algorithm> #include <bits/stdc++.h> #include <ctime> #include <ext/pb_ds/assoc_container.hpp> #include <vector> #define str string #define dbl double #define ll long long int #define ull unsigned long long int #define vl vector<ll> #define vs vector<str> #define pll pair<ll, ll> #define vll vector<pll> #define sl set<ll> #define pb push_back #define mp make_pair #define ub upper_bound #define lb lower_bound #define BS binary_search #define ff first #define ss second #define fast \ ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); \ srand(time(NULL)); #define fr(i, a, b) for (long long i = a; i < b; i++) #define nfr(i, a, b) for (long long i = a; i <= b; i++) #define psl pair<str, ll> #define pls pair<ll, str> #define pss pair<str, str> #define lcm(a, b) (a * b) / __gcd(a, b) #define ALL(a) a.begin(), a.end() #define stl stack<ll> #define coml complex<ll> #define INF 0x3f3f3f3f3f3f3f3f #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define read(v, n) fr(i, 0, n) cin >> v[i]; #define print(x) \ fr(i, 0, x.size()) cout << x[i] << " "; \ cout << "\n"; const ll MOD = 1e9 + 7; const ll N = 2e5 + 5; using namespace std; using namespace __gnu_pbds; void solve() { ll n, k; cin >> n >> k; vl v(n); read(v, n); vl dp(n, INF); dp[0] = 0, dp[1] = abs(v[0] - v[1]); // fr(i,2,k){ // fr(j,1,k+1){ // if(i-j>=0)dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j])); // } // } fr(i, 2, n) { fr(j, 1, k + 1) { if (i - j >= 0) dp[i] = min(dp[i], dp[i - j] + abs(v[i] - v[i - j])); } } // print(dp); cout << dp[n - 1]; } int main() { fast ll t; t = 1; // cin>>t; while (t--) { solve(); } return 0; }
[ "call.remove" ]
958,102
958,103
u721374917
cpp
p03161
// THIS IS MY NINJA WAY #include <algorithm> #include <bits/stdc++.h> #include <ctime> #include <ext/pb_ds/assoc_container.hpp> #include <vector> #define str string #define dbl double #define ll long long int #define ull unsigned long long int #define vl vector<ll> #define vs vector<str> #define pll pair<ll, ll> #define vll vector<pll> #define sl set<ll> #define pb push_back #define mp make_pair #define ub upper_bound #define lb lower_bound #define BS binary_search #define ff first #define ss second #define fast \ ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); \ srand(time(NULL)); #define fr(i, a, b) for (long long i = a; i < b; i++) #define nfr(i, a, b) for (long long i = a; i <= b; i++) #define psl pair<str, ll> #define pls pair<ll, str> #define pss pair<str, str> #define lcm(a, b) (a * b) / __gcd(a, b) #define ALL(a) a.begin(), a.end() #define stl stack<ll> #define coml complex<ll> #define INF 0x3f3f3f3f3f3f3f3f #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define read(v, n) fr(i, 0, n) cin >> v[i]; #define print(x) \ fr(i, 0, x.size()) cout << x[i] << " "; \ cout << "\n"; const ll MOD = 1e9 + 7; const ll N = 2e5 + 5; using namespace std; using namespace __gnu_pbds; void solve() { ll n, k; cin >> n >> k; vl v(n); read(v, n); vl dp(n, INF); dp[0] = 0, dp[1] = abs(v[0] - v[1]); fr(i, 2, k) { fr(j, 1, k + 1) { if (i - j >= 0) dp[i] = min(dp[i], dp[i - j] + abs(v[i] - v[i - j])); } } fr(i, k, n) { fr(j, 1, k + 1) { if (i - j >= 0) dp[i] = min(dp[i], dp[i - j] + abs(v[i] - v[i - j])); } } print(dp); cout << dp[n - 1]; } int main() { fast //#ifndef ONLINE_JUDGE // freopen("input.txt", "r" , stdin); // freopen("output.txt", "w" , stdout); //#endif ll t; t = 1; // cin>>t; while (t--) { solve(); } return 0; }
// THIS IS MY NINJA WAY #include <algorithm> #include <bits/stdc++.h> #include <ctime> #include <ext/pb_ds/assoc_container.hpp> #include <vector> #define str string #define dbl double #define ll long long int #define ull unsigned long long int #define vl vector<ll> #define vs vector<str> #define pll pair<ll, ll> #define vll vector<pll> #define sl set<ll> #define pb push_back #define mp make_pair #define ub upper_bound #define lb lower_bound #define BS binary_search #define ff first #define ss second #define fast \ ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); \ srand(time(NULL)); #define fr(i, a, b) for (long long i = a; i < b; i++) #define nfr(i, a, b) for (long long i = a; i <= b; i++) #define psl pair<str, ll> #define pls pair<ll, str> #define pss pair<str, str> #define lcm(a, b) (a * b) / __gcd(a, b) #define ALL(a) a.begin(), a.end() #define stl stack<ll> #define coml complex<ll> #define INF 0x3f3f3f3f3f3f3f3f #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define read(v, n) fr(i, 0, n) cin >> v[i]; #define print(x) \ fr(i, 0, x.size()) cout << x[i] << " "; \ cout << "\n"; const ll MOD = 1e9 + 7; const ll N = 2e5 + 5; using namespace std; using namespace __gnu_pbds; void solve() { ll n, k; cin >> n >> k; vl v(n); read(v, n); vl dp(n, INF); dp[0] = 0, dp[1] = abs(v[0] - v[1]); fr(i, 2, k) { fr(j, 1, k + 1) { if (i - j >= 0) dp[i] = min(dp[i], dp[i - j] + abs(v[i] - v[i - j])); } } fr(i, k, n) { fr(j, 1, k + 1) { if (i - j >= 0) dp[i] = min(dp[i], dp[i - j] + abs(v[i] - v[i - j])); } } // print(dp); cout << dp[n - 1]; } int main() { fast //#ifndef ONLINE_JUDGE // freopen("input.txt", "r" , stdin); // freopen("output.txt", "w" , stdout); //#endif ll t; t = 1; // cin>>t; while (t--) { solve(); } return 0; }
[ "call.remove" ]
958,104
958,105
u721374917
cpp
p03161
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> h(N), dp(N, 0); for (int i = 0; i < N; i++) { cin >> h[i]; } for (int i = 1; i < N; i++) { if (i == 1) { dp[1] = abs(h[1] - h[0]); continue; } int MIN = 100000; int k = min(i, K); for (int j = 1; j < k + 1; j++) { MIN = min(MIN, dp[i - j] + abs(h[i] - h[i - j])); } dp[i] = MIN; } cout << dp[N - 1] << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> h(N), dp(N, 0); for (int i = 0; i < N; i++) { cin >> h[i]; } for (int i = 1; i < N; i++) { if (i == 1) { dp[1] = abs(h[1] - h[0]); continue; } int MIN = 1000000000; int k = min(i, K); for (int j = 1; j < k + 1; j++) { MIN = min(MIN, dp[i - j] + abs(h[i] - h[i - j])); } dp[i] = MIN; } cout << dp[N - 1] << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
958,112
958,113
u401686269
cpp
p03161
#include <bits/stdc++.h> using namespace std; #define MAX 100007 #define MOD 1000000007 long long frog(long long arr[], int n, int k) { long long output[n + 1]; for (int i = 0; i < n; i++) output[i] = INT_MAX; output[0] = 0; for (int i = 1; i < k; i++) { for (int j = i - 1; j >= 0; j--) { if (output[j] + abs(arr[i] - arr[j]) < output[i]) output[i] = output[j] + abs(arr[i] - arr[j]); } } for (int i = k; i < n; i++) { for (int j = i - 1; j >= i - k; j--) { if (output[j] + abs(arr[i] - arr[j]) < output[i]) output[i] = output[j] + abs(arr[i] - arr[j]); } } return output[n - 1]; } int main() { int n; cin >> n; int k; cin >> k; long long arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; cout << frog(arr, n, k); return 0; }
#include <bits/stdc++.h> using namespace std; #define MAX 100007 #define MOD 1000000007 long long frog(long long arr[], int n, int k) { long long output[n + 1]; for (int i = 0; i < n; i++) output[i] = INT_MAX; output[0] = 0; for (int i = 1; i < min(k, n); i++) { for (int j = i - 1; j >= 0; j--) { if (output[j] + abs(arr[i] - arr[j]) < output[i]) output[i] = output[j] + abs(arr[i] - arr[j]); } } for (int i = k; i < n; i++) { for (int j = i - 1; j >= i - k; j--) { if (output[j] + abs(arr[i] - arr[j]) < output[i]) output[i] = output[j] + abs(arr[i] - arr[j]); } } return output[n - 1]; } int main() { int n; cin >> n; int k; cin >> k; long long arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; cout << frog(arr, n, k); return 0; }
[ "control_flow.loop.for.condition.change", "call.add", "call.arguments.add" ]
958,114
958,115
u070400236
cpp
p03161
#include <algorithm> #include <iostream> using namespace std; int n, k, a[100005], dp[100005]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } dp[0] = 0; dp[1] = abs(a[1] - a[0]); for (int i = 2; i < n; i++) { int b1 = 100000; for (int j = 1; j <= k; j++) { if (i - j >= 0) b1 = min(b1, abs(a[i - j] - a[i]) + dp[i - j]); } dp[i] = b1; // cout<<dp[i]<<"\n"; } /*for(int i=0;i<n;i++){ cout<<dp[i]<<" "; } cout<<"\n";*/ cout << dp[n - 1]; return 0; }
#include <algorithm> #include <iostream> using namespace std; int n, k, a[100005], dp[100005]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } dp[0] = 0; dp[1] = abs(a[1] - a[0]); for (int i = 2; i < n; i++) { int b1 = 1000000005; for (int j = 1; j <= k; j++) { if (i - j >= 0) b1 = min(b1, abs(a[i - j] - a[i]) + dp[i - j]); } dp[i] = b1; // cout<<dp[i]<<"\n"; } /*for(int i=0;i<n;i++){ cout<<dp[i]<<" "; } cout<<"\n";*/ cout << dp[n - 1]; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
958,128
958,129
u193834181
cpp
p03161
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int arr[n] = {}; for (int i = 0; i < n; i++) { cin >> arr[i]; } int dp[n] = {}; for (int i = 0; i < n; i++) { dp[i] = 100000; } dp[0] = 0; dp[1] = abs(arr[1] - arr[0]); for (int i = 2; i < n; i++) { for (int j = i - 1; j >= max(i - k, 0); j--) { dp[i] = min(dp[i], dp[j] + abs(arr[i] - arr[j])); } } cout << dp[n - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int arr[n] = {}; for (int i = 0; i < n; i++) { cin >> arr[i]; } int dp[n] = {}; for (int i = 0; i < n; i++) { dp[i] = INT_MAX; } dp[0] = 0; dp[1] = abs(arr[1] - arr[0]); for (int i = 2; i < n; i++) { for (int j = i - 1; j >= max(i - k, 0); j--) { dp[i] = min(dp[i], dp[j] + abs(arr[i] - arr[j])); } } cout << dp[n - 1] << endl; return 0; }
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove" ]
958,130
958,131
u248172048
cpp
p03161
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } vector<int> dp(n); dp[0] = 0; dp[1] = abs(v[0] - v[1]); int x; for (int i = 2; i < n; i++) { x = INT_MAX; for (int j = 0; j < k; j++) { x = min(x, abs(v[i] - v[i - j - 1]) + dp[i - j - 1]); } dp[i] = x; } cout << dp[n - 1] << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } vector<int> dp(n); dp[0] = 0; dp[1] = abs(v[0] - v[1]); int x; for (int i = 2; i < n; i++) { x = INT_MAX; for (int j = 0; j < k && j < i; j++) { x = min(x, abs(v[i] - v[i - j - 1]) + dp[i - j - 1]); } dp[i] = x; } cout << dp[n - 1] << '\n'; return 0; }
[ "control_flow.loop.for.condition.change" ]
958,142
958,143
u407977226
cpp
p03161
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> dp(n); vector<int> h(n); for (int i = 0; i < n; i++) { cin >> h[i]; } dp[0] = 0; dp[1] = abs(h[0] - h[1]); for (int i = 2; i < n; i++) { int cos = 100000; for (int j = 1; j <= k && j <= i; j++) { cos = min(dp[i - j] + abs(h[i - j] - h[i]), cos); } dp[i] = cos; } cout << dp[n - 1]; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> dp(n); vector<int> h(n); for (int i = 0; i < n; i++) { cin >> h[i]; } dp[0] = 0; dp[1] = abs(h[0] - h[1]); for (int i = 2; i < n; i++) { int cos = INT_MAX; for (int j = 1; j <= k && j <= i; j++) { cos = min(dp[i - j] + abs(h[i - j] - h[i]), cos); } dp[i] = cos; } cout << dp[n - 1]; }
[ "variable_declaration.value.change", "identifier.replace.add", "literal.replace.remove" ]
958,144
958,145
u407977226
cpp
p03161
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int stones[n]; for (int i = 0; i < n; i++) { cin >> stones[i]; } vector<int> dp(n, INT_MAX); dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j <= i + k; j++) { if (j < n) { dp[i] = min(dp[j], dp[i] + abs(stones[i] - stones[j])); } } } cout << dp[n - 1]; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int stones[n]; for (int i = 0; i < n; i++) { cin >> stones[i]; } vector<int> dp(n, INT_MAX); dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j <= i + k; j++) { if (j < n) { dp[j] = min(dp[j], dp[i] + abs(stones[i] - stones[j])); } } } cout << dp[n - 1]; return 0; }
[ "assignment.variable.change", "identifier.change", "variable_access.subscript.index.change" ]
958,146
958,147
u034682738
cpp
p03161
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <unordered_map> #include <vector> using namespace std; #define unomap unordered_map #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define itr iterator #define rtr reverse_iterator typedef long long ll; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef set<int> si; typedef set<pi> spi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<vb> vmb; typedef vector<vi> vmi; typedef vector<si> vsi; typedef vector<vpi> vmpi; typedef vector<spi> vspi; inline int readInt() { char c; while (c = getchar(), c < '0' || c > '9') ; bool sign = (c == '-'); if (sign) c = getchar(); int n = c - '0'; while (c = getchar(), !(c < '0' || c > '9')) n = 10 * n + c - '0'; return (sign) ? -n : n; } inline int readLong() { char c; while (c = getchar(), c < '0' || c > '9') ; bool sign = (c == '-'); if (sign) c = getchar(); ll n = c - '0'; while (c = getchar(), !(c < '0' || c > '9')) n = 10 * n + c - '0'; return (sign) ? -n : n; } inline void getInt(int &n) { char c; while (c = getchar(), c < '0' || c > '9') ; bool sign = (c == '-'); if (sign) c = getchar(); n = c - '0'; while (c = getchar(), !(c < '0' || c > '9')) n = n * 10 + (c - '0'); if (sign) n = -n; } inline void getLong(ll &n) { char c; while (c = getchar(), c < '0' || c > '9') ; bool sign = (c == '-'); if (sign) c = getchar(); n = c - '0'; while (c = getchar(), !(c < '0' || c > '9')) n = n * 10 + (c - '0'); if (sign) n = -n; } int query() { return 0; } int main() { int n = readInt(); int k = readInt(); vi a(n); for (int &x : a) x = readInt(); vi dp(n, 0); for (int i = 1; i < n; ++i) { dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]); for (int j = 2; j <= n; ++j) if (i - j >= 0) dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j])); } cout << dp[n - 1]; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <unordered_map> #include <vector> using namespace std; #define unomap unordered_map #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define itr iterator #define rtr reverse_iterator typedef long long ll; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef set<int> si; typedef set<pi> spi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<vb> vmb; typedef vector<vi> vmi; typedef vector<si> vsi; typedef vector<vpi> vmpi; typedef vector<spi> vspi; inline int readInt() { char c; while (c = getchar(), c < '0' || c > '9') ; bool sign = (c == '-'); if (sign) c = getchar(); int n = c - '0'; while (c = getchar(), !(c < '0' || c > '9')) n = 10 * n + c - '0'; return (sign) ? -n : n; } inline int readLong() { char c; while (c = getchar(), c < '0' || c > '9') ; bool sign = (c == '-'); if (sign) c = getchar(); ll n = c - '0'; while (c = getchar(), !(c < '0' || c > '9')) n = 10 * n + c - '0'; return (sign) ? -n : n; } inline void getInt(int &n) { char c; while (c = getchar(), c < '0' || c > '9') ; bool sign = (c == '-'); if (sign) c = getchar(); n = c - '0'; while (c = getchar(), !(c < '0' || c > '9')) n = n * 10 + (c - '0'); if (sign) n = -n; } inline void getLong(ll &n) { char c; while (c = getchar(), c < '0' || c > '9') ; bool sign = (c == '-'); if (sign) c = getchar(); n = c - '0'; while (c = getchar(), !(c < '0' || c > '9')) n = n * 10 + (c - '0'); if (sign) n = -n; } int query() { return 0; } int main() { int n = readInt(); int k = readInt(); vi a(n); for (int &x : a) x = readInt(); vi dp(n, 0); for (int i = 1; i < n; ++i) { dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]); for (int j = 2; j <= k; ++j) if (i - j >= 0) dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j])); } cout << dp[n - 1]; return 0; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
958,148
958,149
u503230266
cpp
p03161
#include <bits/stdc++.h> #include <bitset> #include <map> #include <set> #define rep(i, a, b) for (i = a; i < b; i++) #define itrep(at) for (auto it = at.begin(); it != at.end(); it++) #define lli long long int #define pb push_back #define eb emplace_back #define mp make_pair #define db double #define M 1000000007 #define pi 3.1415926535897932384626433832795028841971 #define MAX 100005 using namespace std; lli min(lli a, lli b) { return a < b ? a : b; } lli min(lli a, lli b, lli c) { a = min(a, b); a = min(a, c); return a; } lli max(lli a, lli b) { return a > b ? a : b; } lli max(lli a, lli b, lli c) { a = max(a, b); a = max(a, c); return a; } lli dsum(lli n) { lli ans = 0; while (n) { ans += (n % 10); n /= 10; } return ans; } struct pll { lli x, y; }; bool comp(pll a, pll b) { if (a.x == b.x) return a.y < b.y; else return a.x < b.x; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); char ch; db aa, bb, cc; string s1, s2, s3; lli i, j, k, a, b, c, n, m, sum = 0, ans = 0, temp; cin >> n >> k; lli h[n]; rep(i, 0, n) cin >> h[i]; vector<lli> dp(n, M); dp[0] = 0; dp[1] = abs(h[0] - h[1]); for (i = 2; i < n; i++) { m = M; for (j = 1; j <= k; j++) { m = min(m, dp[i - j] + abs(h[i] - h[i - j])); } dp[i] = m; } cout << dp[n - 1] << endl; return 0; } /* UJJWAL KESHRI */
#include <bits/stdc++.h> #include <bitset> #include <map> #include <set> #define rep(i, a, b) for (i = a; i < b; i++) #define itrep(at) for (auto it = at.begin(); it != at.end(); it++) #define lli long long int #define pb push_back #define eb emplace_back #define mp make_pair #define db double #define M 1000000007 #define pi 3.1415926535897932384626433832795028841971 #define MAX 100005 using namespace std; lli min(lli a, lli b) { return a < b ? a : b; } lli min(lli a, lli b, lli c) { a = min(a, b); a = min(a, c); return a; } lli max(lli a, lli b) { return a > b ? a : b; } lli max(lli a, lli b, lli c) { a = max(a, b); a = max(a, c); return a; } lli dsum(lli n) { lli ans = 0; while (n) { ans += (n % 10); n /= 10; } return ans; } struct pll { lli x, y; }; bool comp(pll a, pll b) { if (a.x == b.x) return a.y < b.y; else return a.x < b.x; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); char ch; db aa, bb, cc; string s1, s2, s3; lli i, j, k, a, b, c, n, m, sum = 0, ans = 0, temp; cin >> n >> k; lli h[n]; rep(i, 0, n) cin >> h[i]; vector<lli> dp(n, M); dp[0] = 0; dp[1] = abs(h[0] - h[1]); for (i = 2; i < n; i++) { m = M; for (j = 1; j <= k && j <= i; j++) { m = min(m, dp[i - j] + abs(h[i] - h[i - j])); } dp[i] = m; } cout << dp[n - 1] << endl; return 0; } /* UJJWAL KESHRI */
[ "control_flow.loop.for.condition.change" ]
958,152
958,153
u529781102
cpp
p03161
#include <bits/stdc++.h> using namespace std; int frog(std::vector<int> v, int n, int k) { int dp[100001] = {0}; dp[0] = 0; dp[1] = abs(v[0] - v[1]); for (int i = 2; i <= n; i++) { int ans = INT_MAX; for (int j = 1; j <= k; j++) { int a1 = 0; if ((i - j) > 0) { a1 = dp[i - j] + abs(v[i] - v[i - j]); } else { continue; } ans = min(ans, a1); } dp[i] = ans; } return dp[n - 1]; } int main() { int n; cin >> n; int k; cin >> k; std::vector<int> v; for (int i = 0; i < n; i++) { int a; cin >> a; v.push_back(a); } int ans = frog(v, n, k); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int frog(std::vector<int> v, int n, int k) { int dp[100001] = {0}; dp[0] = 0; dp[1] = abs(v[0] - v[1]); for (int i = 2; i <= n; i++) { int ans = INT_MAX; for (int j = 1; j <= k; j++) { int a1 = 0; if ((i - j) >= 0) { a1 = dp[i - j] + abs(v[i] - v[i - j]); } else { break; } ans = min(ans, a1); } dp[i] = ans; } return dp[n - 1]; } int main() { int n; cin >> n; int k; cin >> k; std::vector<int> v; for (int i = 0; i < n; i++) { int a; cin >> a; v.push_back(a); } int ans = frog(v, n, k); cout << ans << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "control_flow.continue.remove", "control_flow.break.add" ]
958,154
958,155
u004244461
cpp
p03161
#include <bits/stdc++.h> #define endl "\n" #define ioss \ ios::sync_with_stdio(false); \ cin.tie(NULL); #define pb push_back #define eb emplace_back //#define int long long typedef long long ll; using namespace std; int main() { ioss int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } ll dp[100005]; for (int i = 0; i < 100005; i++) dp[i] = 100000; dp[0] = 0; dp[1] = abs(a[1] - a[0]); // for(int i=0;i<20;i++) cout<<dp[i]<<endl; for (int i = 0; i < n; i++) { for (int j = i + 1; j <= i + k; j++) { if (j < n) { dp[j] = min(dp[j], dp[i] + ll(abs(a[j] - a[i]))); } } } cout << dp[n - 1] << endl; return 0; }
#include <bits/stdc++.h> #define endl "\n" #define ioss \ ios::sync_with_stdio(false); \ cin.tie(NULL); #define pb push_back #define eb emplace_back //#define int long long typedef long long ll; using namespace std; int main() { ioss int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } ll dp[100005]; for (int i = 0; i < 100005; i++) dp[i] = 10000000000; dp[0] = 0; dp[1] = abs(a[1] - a[0]); // for(int i=0;i<20;i++) cout<<dp[i]<<endl; for (int i = 0; i < n; i++) { for (int j = i + 1; j <= i + k; j++) { if (j < n) { dp[j] = min(dp[j], dp[i] + ll(abs(a[j] - a[i]))); } } } cout << dp[n - 1] << endl; return 0; }
[ "literal.number.change", "assignment.value.change" ]
958,158
958,159
u849815280
cpp
p03161
/* Author: Qaseem Hasan alias Mikepayne14(Codeforces,Atcoder) qaseem_hasan_ (Codechef,HackerRank,HackerEarth) */ #include <bits/stdc++.h> using namespace std; //--------------------------------------------------------- typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pair<int, int>> vpii; typedef priority_queue<int, vector<int>, greater<int>> revpq; const int INF = (int)1e9; const int EPS = 1e-6; const int mod = 1000000007; const long double PI = 3.14159265359; const int dx4[4] = {0, 1, 0, -1}; const int dy4[4] = {-1, 0, 1, 0}; const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1}; #define acc accumulate #define eb emplace_back #define F first #define S second #define MP make_pair #define filcon(v, x) iota(all(v), x) #define repi(n) for (int i = 0; i < n; ++i) //#define erase(v,e) v.erase(std::remove(v.begin(), v.end(), e), v.end()) #define sqr(x) ((x) * (x)) #define MEM(a, b) memset(a, b, sizeof(a)) #define all(cont) cont.begin(), cont.end() #define rall(cont) cont.end(), cont.begin() #define inrange(i, a, b) ((i >= min(a, b)) && (i <= max(a, b))) // #define min_all(a,b,c,d,...) min({a,b,c,d,...}) #define FAST_IO \ ios::sync_with_stdio(false); \ cin.tie(nullptr); #define make_unique(v) \ sort(all(v)); \ v.erase(unique(all(v)), v.end()); #define printv(v) \ for (auto i : v) \ cout << i << " " #define trace(x) cout << #x << " = { " << x << " }" << khatam #define khatam '\n' #define test \ int t; \ cin >> t; \ repi(t) { \ solve(); \ cout << khatam; \ } #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #define time__(d) \ for (auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \ blockTime.second; \ debug("%s: %ld ms\n", d, \ chrono::duration_cast<chrono::milliseconds>( \ chrono::high_resolution_clock::now() - blockTime.first) \ .count()), \ blockTime.second = false) //-------------------------------------------------------- inline bool grid_inside(int x, int y, int n, int m) { return x >= 1 && x <= n && y >= 1 && y <= m; } template <typename T> T lcm(T a, T b) { return (a * b) / __gcd(a, b); } template <typename T> T Dis(T x1, T y1, T x2, T y2) { return sqrt(sqr(x1 - x2) + sqr(y1 - y2)); } template <typename T> T Angle(T x1, T y1, T x2, T y2) { return atan((double)(y1 - y2) / (double)(x1 - x2)); } inline int Set(int N, int pos) { return N = N | (1 << pos); } inline int Reset(int N, int pos) { return N = N & ~(1 << pos); } inline bool Check(int N, int pos) { return (bool)(N & (1 << pos)); } template <class T, class X> inline T togglebit(T a, X i) { T t = 1; return (a ^ (t << i)); } //-------------------------------------------------------- bool compare(const pair<int, int> &i, const pair<int, int> &j) { return i.F < j.F; } int LSOne(ll n) { return log2(n & -n) + 1; } int rangeClear(int n, int i, int j) { int ones = ~0; int a = ones << (j + 1); int b = (i << 2) - 1; int mask = a | b; int ans = n & mask; return ans; } ll mul_mod(ll x, ll y, ll mod) { ll i = 0, j = x; while (y > 0) { if (y & 1) { i = (i + j) % mod; } j = (j + j) % mod; y >>= 1; } return i; } ll fast_power(int a, int x) { if (x == 0) return 1; else if (x == 1) return a; else { ll R = fast_power(a, x >> 1); if (!(x & 1)) return R * R; else return R * a * R; } } ll fast_power_unlocked(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) { res = mul_mod(res, a, mod); } a = mul_mod(a, a, mod); n = n >> 1; } return res; } ll modInverse(ll A, ll M) { return fast_power_unlocked(A, M - 2, M); } const int maxn = 1e5 + 5; ll n, k; ll dp[maxn], cost[maxn] = {}; void solve() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> cost[i]; MEM(dp, 0); dp[1] = 0; ll mini; for (int i = 2; i <= n; i++) { mini = LLONG_MAX; for (int j = 1; j <= k; j++) { if (i - j < 0) continue; mini = min(mini, (dp[i - j] + abs(cost[i - j] - cost[i]))); } if (mini == LLONG_MAX) dp[i] = 0; else dp[i] = mini; } cout << dp[n]; } int main() { FAST_IO; //------------------------------------------------------- time__("Time Taken") { solve(); } }
/* Author: Qaseem Hasan alias Mikepayne14(Codeforces,Atcoder) qaseem_hasan_ (Codechef,HackerRank,HackerEarth) */ #include <bits/stdc++.h> using namespace std; //--------------------------------------------------------- typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pair<int, int>> vpii; typedef priority_queue<int, vector<int>, greater<int>> revpq; const int INF = (int)1e9; const int EPS = 1e-6; const int mod = 1000000007; const long double PI = 3.14159265359; const int dx4[4] = {0, 1, 0, -1}; const int dy4[4] = {-1, 0, 1, 0}; const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1}; #define acc accumulate #define eb emplace_back #define F first #define S second #define MP make_pair #define filcon(v, x) iota(all(v), x) #define repi(n) for (int i = 0; i < n; ++i) //#define erase(v,e) v.erase(std::remove(v.begin(), v.end(), e), v.end()) #define sqr(x) ((x) * (x)) #define MEM(a, b) memset(a, b, sizeof(a)) #define all(cont) cont.begin(), cont.end() #define rall(cont) cont.end(), cont.begin() #define inrange(i, a, b) ((i >= min(a, b)) && (i <= max(a, b))) // #define min_all(a,b,c,d,...) min({a,b,c,d,...}) #define FAST_IO \ ios::sync_with_stdio(false); \ cin.tie(nullptr); #define make_unique(v) \ sort(all(v)); \ v.erase(unique(all(v)), v.end()); #define printv(v) \ for (auto i : v) \ cout << i << " " #define trace(x) cout << #x << " = { " << x << " }" << khatam #define khatam '\n' #define test \ int t; \ cin >> t; \ repi(t) { \ solve(); \ cout << khatam; \ } #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #define time__(d) \ for (auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \ blockTime.second; \ debug("%s: %ld ms\n", d, \ chrono::duration_cast<chrono::milliseconds>( \ chrono::high_resolution_clock::now() - blockTime.first) \ .count()), \ blockTime.second = false) //-------------------------------------------------------- inline bool grid_inside(int x, int y, int n, int m) { return x >= 1 && x <= n && y >= 1 && y <= m; } template <typename T> T lcm(T a, T b) { return (a * b) / __gcd(a, b); } template <typename T> T Dis(T x1, T y1, T x2, T y2) { return sqrt(sqr(x1 - x2) + sqr(y1 - y2)); } template <typename T> T Angle(T x1, T y1, T x2, T y2) { return atan((double)(y1 - y2) / (double)(x1 - x2)); } inline int Set(int N, int pos) { return N = N | (1 << pos); } inline int Reset(int N, int pos) { return N = N & ~(1 << pos); } inline bool Check(int N, int pos) { return (bool)(N & (1 << pos)); } template <class T, class X> inline T togglebit(T a, X i) { T t = 1; return (a ^ (t << i)); } //-------------------------------------------------------- bool compare(const pair<int, int> &i, const pair<int, int> &j) { return i.F < j.F; } int LSOne(ll n) { return log2(n & -n) + 1; } int rangeClear(int n, int i, int j) { int ones = ~0; int a = ones << (j + 1); int b = (i << 2) - 1; int mask = a | b; int ans = n & mask; return ans; } ll mul_mod(ll x, ll y, ll mod) { ll i = 0, j = x; while (y > 0) { if (y & 1) { i = (i + j) % mod; } j = (j + j) % mod; y >>= 1; } return i; } ll fast_power(int a, int x) { if (x == 0) return 1; else if (x == 1) return a; else { ll R = fast_power(a, x >> 1); if (!(x & 1)) return R * R; else return R * a * R; } } ll fast_power_unlocked(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) { res = mul_mod(res, a, mod); } a = mul_mod(a, a, mod); n = n >> 1; } return res; } ll modInverse(ll A, ll M) { return fast_power_unlocked(A, M - 2, M); } const int maxn = 1e5 + 5; ll n, k; ll dp[maxn], cost[maxn] = {}; void solve() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> cost[i]; MEM(dp, 0); dp[1] = 0; ll mini; for (int i = 2; i <= n; i++) { mini = LLONG_MAX; for (int j = 1; j <= k; j++) { if (i - j <= 0) continue; mini = min(mini, (dp[i - j] + abs(cost[i - j] - cost[i]))); } if (mini == LLONG_MAX) dp[i] = 0; else dp[i] = mini; } cout << dp[n]; } int main() { FAST_IO; //------------------------------------------------------- time__("Time Taken") { solve(); } }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
958,173
958,174
u649440112
cpp
p03161
// INCLUDE //------------------------------------------ #include <algorithm> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <math.h> #include <string> #include <vector> // DEFINE //------------------------------------------ #define ll long long #define ALLv(a) (a).begin(), (a).end() #define ALL(a, n) (a), (a) + n #define vi vector<long long> #define vd vector<long double> #define vs vector<string> // CONST //------------------------------------------ #define INF 1010000000000000017LL #define MOD 1000000007LL #define EPS 1e-12 #define PI 3.14159265358979323846 // REPEAT //------------------------------------------ #define FOR(i, m, n) for (ll(i) = (m); (i) < (n); (i)++) #define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define REPS(i, x) for (ll(i) = 1; (i) <= (x); (i)++) #define RREP(i, x) for (ll(i) = (x)-1; (i) >= 0; (i)--) #define RREPS(i, x) for (ll(i) = (x); (i) > 0; (i)--) #define WREP(i, in, j, jn) REP(i, in) REP(j, jn) using namespace std; //------------------------------------------- int main(void) { ll N, K; cin >> N >> K; ll h[N + 1]; REPS(i, N) cin >> h[i]; vi dp(N * 2 + 1, INF); dp[1] = 0; REPS(i, N) { REPS(k, K) dp[i + k] = min(dp[i + k], dp[i] + labs(h[i + k] - h[i])); } cout << dp[N] << endl; return 0; }
// INCLUDE //------------------------------------------ #include <algorithm> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <math.h> #include <string> #include <vector> // DEFINE //------------------------------------------ #define ll long long #define ALLv(a) (a).begin(), (a).end() #define ALL(a, n) (a), (a) + n #define vi vector<long long> #define vd vector<long double> #define vs vector<string> // CONST //------------------------------------------ #define INF 1010000000000000017LL #define MOD 1000000007LL #define EPS 1e-12 #define PI 3.14159265358979323846 // REPEAT //------------------------------------------ #define FOR(i, m, n) for (ll(i) = (m); (i) < (n); (i)++) #define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define REPS(i, x) for (ll(i) = 1; (i) <= (x); (i)++) #define RREP(i, x) for (ll(i) = (x)-1; (i) >= 0; (i)--) #define RREPS(i, x) for (ll(i) = (x); (i) > 0; (i)--) #define WREP(i, in, j, jn) REP(i, in) REP(j, jn) using namespace std; //------------------------------------------- int main(void) { ll N, K; cin >> N >> K; ll h[N + 1]; REPS(i, N) cin >> h[i]; vi dp(N * 2 + 2, INF); dp[1] = 0; REPS(i, N) { REPS(k, K) dp[i + k] = min(dp[i + k], dp[i] + labs(h[i + k] - h[i])); } cout << dp[N] << endl; return 0; }
[ "literal.number.change", "call.arguments.change", "expression.operation.binary.change" ]
958,179
958,180
u334644046
cpp
p03161
#include <iostream> #include <vector> using namespace std; #define N_MAX 100000 long long dp[N_MAX + 1]; long long N, K; vector<long long> h; int main(void) { cin >> N >> K; h.resize(N); for (int i = 0; i < N; i++) { cin >> h[i]; } for (int i = 0; i < N + 1; i++) dp[i] = N_MAX; dp[0] = 0; for (int i = 0; i < N; i++) { for (int j = 1; j <= K; j++) { dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j])); } } cout << dp[N - 1] << endl; return 0; }
#include <iostream> #include <vector> using namespace std; #define N_MAX 100000 long long dp[N_MAX + 1]; long long N, K; vector<long long> h; int main(void) { cin >> N >> K; h.resize(N); for (int i = 0; i < N; i++) { cin >> h[i]; } for (int i = 0; i < N + 1; i++) dp[i] = 1000000000; dp[0] = 0; for (int i = 0; i < N; i++) { for (int j = 1; j <= K; j++) { dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j])); } } cout << dp[N - 1] << endl; return 0; }
[ "assignment.value.change", "identifier.replace.remove", "literal.replace.add" ]
958,181
958,182
u271951875
cpp
p03161
#include <bits/stdc++.h> using namespace std; int mn = INT_MAX; int f(int a[], int n, int i, int c, int k) { int cst[n]; cst[0] = 0; cst[1] = abs(a[1] - a[0]); for (int i = 2; i < n; i++) { int m = INT_MAX; for (int j = 1; j <= k; j++) { if ((i - j) < 0) break; int u = abs(a[i] - a[i - j]) + cst[i - k]; m = min(u, m); } cst[i] = m; } return cst[n - 1]; } int main() { int n, k; cin >> n >> k; int a[n], i; for (int i = 0; i < n; i++) cin >> a[i]; mn = f(a, n, 0, 0, k); cout << mn << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int mn = INT_MAX; int f(int a[], int n, int i, int c, int k) { int cst[n]; cst[0] = 0; cst[1] = abs(a[1] - a[0]); for (int i = 2; i < n; i++) { int m = INT_MAX; for (int j = 1; j <= k; j++) { if ((i - j) < 0) break; int u = abs(a[i] - a[i - j]) + cst[i - j]; m = min(u, m); } cst[i] = m; } return cst[n - 1]; } int main() { int n, k; cin >> n >> k; int a[n], i; for (int i = 0; i < n; i++) cin >> a[i]; mn = f(a, n, 0, 0, k); cout << mn << endl; return 0; }
[ "identifier.change", "variable_access.subscript.index.change", "expression.operation.binary.change" ]
958,183
958,184
u082587844
cpp
p03161
#include <algorithm> #include <cmath> #include <iostream> #include <vector> using namespace std; typedef long long ll; /*bool subseq(string s,string t){ ll y=0; for(ll i=0;y<s.size()&& i<t.size();i++){ if(s[y]==t[i]){ y++; } } if(y==s.size()) return true; else return false; }*/ void solve(ll a[], ll n, ll k) { vector<ll> dp(n + 1, 100005); ll c = 0; dp[0] = 0; for (ll i = 1; i < n; i++) { for (ll j = i; c <= k && j >= 0; j--) { dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j])); c++; } c = 0; } // for(ll i=0;i<n;i++) // cout<<dp[i]<<" "; cout << dp[n - 1]; } int main() { ll n, k; cin >> n >> k; ll a[n]; for (ll i = 0; i < n; i++) { cin >> a[i]; } solve(a, n, k); }
#include <algorithm> #include <cmath> #include <iostream> #include <vector> using namespace std; typedef long long ll; void solve(ll a[], ll n, ll k) { vector<ll> dp(n + 1, 100000000005); ll c = 1; dp[0] = 0; for (ll i = 1; i < n; i++) { for (ll j = i - 1; c <= k && j >= 0; j--) { dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j])); c++; } c = 1; } // for(ll i=0;i<n;i++) // cout<<dp[i]<<" "; cout << dp[n - 1]; } int main() { ll n, k; cin >> n >> k; ll a[n]; for (ll i = 0; i < n; i++) { cin >> a[i]; } solve(a, n, k); }
[ "literal.number.change", "call.arguments.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "assignment.value.change" ]
958,187
958,186
u408648220
cpp
p03161
#include <algorithm> #include <cmath> #include <iostream> #include <vector> using namespace std; typedef long long ll; /*bool subseq(string s,string t){ ll y=0; for(ll i=0;y<s.size()&& i<t.size();i++){ if(s[y]==t[i]){ y++; } } if(y==s.size()) return true; else return false; }*/ void solve(ll a[], ll n, ll k) { vector<ll> dp(n + 1, 100005); ll c = 1; dp[0] = 0; for (ll i = 1; i < n; i++) { for (ll j = i - 1; c <= k && j >= 0; j--) { dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j])); c++; } c = 1; } // for(ll i=0;i<n;i++) // cout<<dp[i]<<" "; cout << dp[n - 1]; } int main() { ll n, k; cin >> n >> k; ll a[n]; for (ll i = 0; i < n; i++) { cin >> a[i]; } solve(a, n, k); }
#include <algorithm> #include <cmath> #include <iostream> #include <vector> using namespace std; typedef long long ll; void solve(ll a[], ll n, ll k) { vector<ll> dp(n + 1, 100000000005); ll c = 1; dp[0] = 0; for (ll i = 1; i < n; i++) { for (ll j = i - 1; c <= k && j >= 0; j--) { dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j])); c++; } c = 1; } // for(ll i=0;i<n;i++) // cout<<dp[i]<<" "; cout << dp[n - 1]; } int main() { ll n, k; cin >> n >> k; ll a[n]; for (ll i = 0; i < n; i++) { cin >> a[i]; } solve(a, n, k); }
[ "literal.number.change", "call.arguments.change" ]
958,188
958,186
u408648220
cpp
p03161
#include <bits/stdc++.h> #define int long long int #define IOS ios_base::sync_with_stdio(false), cin.tie(NULL); #define fr(i, a, b) for (int i = a; i <= b; i++) #define rf(j, b, a) for (int j = b; j >= a; j--) #define frr(k, a, b) for (int k = a; k <= b; k++) #define mp make_pair #define pb push_back #define MOD 1000000007 #define ss second #define ff first using namespace std; typedef pair<int, int> pii; typedef pair<pii, int> ppii; #define E 2000 bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { if (a.first == b.first) { return (a.second < b.second); } else { return (a.first > b.first); } } bool sortin(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } signed main() { IOS int n, k; cin >> n >> k; int h[n + 1]; int dp[n + 1]; dp[0] = dp[1] = 0; for (int i = 1; i <= n; i++) { cin >> h[i]; } dp[2] = abs(h[2] - h[1]); for (int i = 3; i <= n; i++) { int val = INT_MAX; for (int j = i - 1; j >= max((i - k), 0 * 1LL); j--) { int hp = abs(h[i] - h[j]); val = min(val, hp + dp[j]); } dp[i] = val; } cout << dp[n] << endl; } /* int h1 = abs(h[i]-h[i-1]); int h2 = abs(h[i]-h[i-2]); dp[i] = min(h1+dp[i-1],h2+dp[i-2]); */
#include <bits/stdc++.h> #define int long long int #define IOS ios_base::sync_with_stdio(false), cin.tie(NULL); #define fr(i, a, b) for (int i = a; i <= b; i++) #define rf(j, b, a) for (int j = b; j >= a; j--) #define frr(k, a, b) for (int k = a; k <= b; k++) #define mp make_pair #define pb push_back #define MOD 1000000007 #define ss second #define ff first using namespace std; typedef pair<int, int> pii; typedef pair<pii, int> ppii; #define E 2000 bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { if (a.first == b.first) { return (a.second < b.second); } else { return (a.first > b.first); } } bool sortin(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } signed main() { IOS int n, k; cin >> n >> k; int h[n + 1]; int dp[n + 1]; dp[0] = dp[1] = 0; for (int i = 1; i <= n; i++) { cin >> h[i]; } dp[2] = abs(h[2] - h[1]); for (int i = 3; i <= n; i++) { int val = INT_MAX; for (int j = i - 1; j >= max((i - k), 1 * 1LL); j--) { int hp = abs(h[i] - h[j]); val = min(val, hp + dp[j]); } dp[i] = val; } cout << dp[n] << endl; } /* int h1 = abs(h[i]-h[i-1]); int h2 = abs(h[i]-h[i-2]); dp[i] = min(h1+dp[i-1],h2+dp[i-2]); */
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "call.arguments.change", "expression.operation.binary.change" ]
958,192
958,193
u553066935
cpp
p03161
#include <bits/stdc++.h> using namespace std; const int mod = 1e9; int main() { long long int n, k, i, j, p; cin >> n >> k; long long int ar[n]; for (i = 0; i < n; i++) { cin >> ar[i]; } long long int dp[n]; memset(dp, mod, sizeof(dp)); dp[0] = 0; for (i = 0; i < n; i++) { for (j = i + 1; j <= i + k; j++) { if (j < n) dp[j] = min(dp[j], (abs(ar[j] - ar[i]) + dp[i])); } } /* for(i=0;i<n; i++){ cout<<dp[i]<<" "; }*/ cout << dp[n - 1]; return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int main() { long long int n, k, i, j, p; cin >> n >> k; long long int ar[n]; for (i = 0; i < n; i++) { cin >> ar[i]; } long long int dp[n]; memset(dp, mod, sizeof(dp)); dp[0] = 0; for (i = 0; i < n; i++) { for (j = i + 1; j <= i + k; j++) { if (j < n) dp[j] = min(dp[j], (abs(ar[j] - ar[i]) + dp[i])); } } /* for(i=0;i<n; i++){ cout<<dp[i]<<" "; }*/ cout << dp[n - 1]; return 0; }
[ "assignment.change" ]
958,194
958,195
u010509890
cpp
p03161
#include <bits/stdc++.h> using namespace std; long long dp[100010]; int main() { int N, K; int h[100015]; cin >> N >> K; for (int i = 0; i < N; i++) cin >> h[i]; for (int i = 0; i < 100010; ++i) dp[i] = INT_MAX; dp[0] = 0; dp[1] = abs(h[1] - h[0]); for (int i = 2; i < N; ++i) { for (int j = 1; j < K + 1; ++j) { if (abs(i - j) < 0) continue; dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j])); } } cout << dp[N - 1] << endl; }
#include <bits/stdc++.h> using namespace std; long long dp[100010]; int main() { int N, K; int h[100015]; cin >> N >> K; for (int i = 0; i < N; i++) cin >> h[i]; for (int i = 0; i < 100010; ++i) dp[i] = LLONG_MAX; dp[0] = 0; dp[1] = abs(h[1] - h[0]); for (int i = 2; i < N; ++i) { for (int j = 1; j < K + 1; ++j) { if (i - j < 0) continue; dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j])); } } cout << dp[N - 1] << endl; }
[ "assignment.value.change", "identifier.change", "control_flow.loop.for.condition.change", "call.remove", "control_flow.branch.if.condition.change" ]
958,200
958,201
u530497183
cpp
p03161
#include <bits/stdc++.h> using namespace std; int x(int arr[], int dp[], int n, int k) { dp[0] = 0; for (int i = 0; i < k; i++) dp[i] = abs(arr[0] - arr[i]); for (int i = k; i < n; i++) { // cout<<arr[i]; int m = INT_MAX; for (int j = i - k; j < i; j++) m = min(m, dp[j] + abs(arr[j] - arr[i])); dp[i] = m; // cout<<dp[i]<<" "; } return dp[n - 1]; } int main() { int t, k; cin >> t >> k; if (k > t) k == t; int arr[t]; for (int i = 0; i < t; i++) { cin >> arr[i]; } int dp[t] = {0}; cout << x(arr, dp, t, k); }
#include <bits/stdc++.h> using namespace std; int x(int arr[], int dp[], int n, int k) { dp[0] = 0; for (int i = 0; i < k; i++) dp[i] = abs(arr[0] - arr[i]); for (int i = k; i < n; i++) { // cout<<arr[i]; int m = INT_MAX; for (int j = i - k; j < i; j++) m = min(m, dp[j] + abs(arr[j] - arr[i])); dp[i] = m; // cout<<dp[i]<<" "; } return dp[n - 1]; } int main() { int t, k; cin >> t >> k; if (k > t) k = t; int arr[t]; for (int i = 0; i < t; i++) { cin >> arr[i]; } int dp[t] = {0}; cout << x(arr, dp, t, k); }
[ "expression.operation.compare.replace.remove", "assignment.replace.add", "misc.typo" ]
958,204
958,205
u802332845
cpp
p03161
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { ll n, k; cin >> n >> k; ll ar[n + 1]; for (ll x = 1; x <= n; x++) { cin >> ar[x]; } ll dp[n + 1]; dp[1] = 0; dp[2] = abs(ar[2] - ar[1]); for (ll x = 3; x <= n; x++) { ll r = INT_MAX; for (ll y = x - 1; y >= max(x - k, (ll)0); y--) { r = min(r, dp[y] + abs(ar[x] - ar[y])); } dp[x] = r; } cout << dp[n]; }
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { ll n, k; cin >> n >> k; ll ar[n + 1]; for (ll x = 1; x <= n; x++) { cin >> ar[x]; } ll dp[n + 1]; dp[1] = 0; dp[2] = abs(ar[2] - ar[1]); for (ll x = 3; x <= n; x++) { ll r = INT_MAX; for (ll y = x - 1; y >= max(x - k, (ll)1); y--) { r = min(r, dp[y] + abs(ar[x] - ar[y])); } dp[x] = r; } cout << dp[n]; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "call.arguments.change", "expression.operation.binary.change" ]
958,225
958,226
u460674262
cpp
p03161
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mp make_pair #define ld long double #define M 1000000000 void printprecise(double l, ll precision) { std::cout << std::fixed; std::cout << std::setprecision(precision); std::cout << l; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } void initialize(ll ar[], ll n) { for (ll x = 0; x < n; x++) ar[x] = x; } void printarray(ll ar[], ll n) { for (ll x = 0; x < n; x++) cout << ar[x] << " "; cout << endl; } void printvector(vector<char> v) { for (ll x = 0; x < v.size(); x++) { cout << v[x] << " "; } cout << endl; } ll root(ll i, ll ar[]) { while (ar[i] != i) { ar[i] = ar[ar[i]]; i = ar[i]; } return i; } void unione(ll a, ll b, ll ar[]) { ll p = root(a, ar); ll q = root(b, ar); ar[p] = ar[q]; } ll bfs(ll n, ll vis[], vector<ll> v[], ll level[]) { list<ll> g; g.pb(n); vis[n] = 1; level[n] = 1; while (!g.empty()) { ll a = g.front(); g.pop_front(); for (ll x = 0; x < v[a].size(); x++) { if (vis[v[a][x]] == 1 && v[a][x] != a) { return level[a] - level[v[a][x]] + 1; } else { g.pb(v[a][x]); vis[v[a][x]] = 1; level[v[a][x]] = level[a] + 1; } } } return 10000000; } int main() { ll n, k; cin >> n >> k; ll ar[n + 1]; for (ll x = 1; x <= n; x++) { cin >> ar[x]; } ll dp[n + 1] = {0}; dp[1] = 0; dp[2] = abs(ar[2] - ar[1]); for (ll x = 3; x <= n; x++) { ll m = 10000000; for (ll y = x - 1; y >= max((ll)0, x - k); y--) { m = min(m, dp[y] + abs(ar[x] - ar[y])); } dp[x] = m; } cout << dp[n]; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mp make_pair #define ld long double #define M 1000000000 void printprecise(double l, ll precision) { std::cout << std::fixed; std::cout << std::setprecision(precision); std::cout << l; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } void initialize(ll ar[], ll n) { for (ll x = 0; x < n; x++) ar[x] = x; } void printarray(ll ar[], ll n) { for (ll x = 0; x < n; x++) cout << ar[x] << " "; cout << endl; } void printvector(vector<char> v) { for (ll x = 0; x < v.size(); x++) { cout << v[x] << " "; } cout << endl; } ll root(ll i, ll ar[]) { while (ar[i] != i) { ar[i] = ar[ar[i]]; i = ar[i]; } return i; } void unione(ll a, ll b, ll ar[]) { ll p = root(a, ar); ll q = root(b, ar); ar[p] = ar[q]; } ll bfs(ll n, ll vis[], vector<ll> v[], ll level[]) { list<ll> g; g.pb(n); vis[n] = 1; level[n] = 1; while (!g.empty()) { ll a = g.front(); g.pop_front(); for (ll x = 0; x < v[a].size(); x++) { if (vis[v[a][x]] == 1 && v[a][x] != a) { return level[a] - level[v[a][x]] + 1; } else { g.pb(v[a][x]); vis[v[a][x]] = 1; level[v[a][x]] = level[a] + 1; } } } return 10000000; } int main() { ll n, k; cin >> n >> k; ll ar[n + 1]; for (ll x = 1; x <= n; x++) { cin >> ar[x]; } ll dp[n + 1] = {0}; dp[1] = 0; dp[2] = abs(ar[2] - ar[1]); for (ll x = 3; x <= n; x++) { ll m = 10000000000000; for (ll y = x - 1; y >= max((ll)1, x - k); y--) { m = min(m, dp[y] + abs(ar[x] - ar[y])); } dp[x] = m; } cout << dp[n]; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "call.arguments.change", "expression.operation.binary.change" ]
958,229
958,228
u460674262
cpp
p03161
#include <bits/stdc++.h> #define IO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define int long long using namespace std; const int MX = 1e5 + 5; int n, k; vector<int> v; int dp[MX]; int solve(int pos) { if (pos > n) return 1e17; if (pos == n) return 0; if (dp[pos] != -1) return dp[pos]; int ans = 1e17, curr_height = v[pos], next_height; for (int i = 1; i <= k; i++) { if (pos + i <= n) { next_height = v[pos + i]; ans = min(ans, solve(pos + i) + abs(curr_height - next_height)); } } return dp[pos] = ans; } int32_t main() { memset(dp, -1, sizeof dp); cin >> n >> k; v.resize(n); for (int i = 1; i <= n; i++) cin >> v[i]; cout << solve(1); return 0; }
#include <bits/stdc++.h> #define IO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define int long long using namespace std; const int MX = 1e5 + 5; int n, k; vector<int> v; int dp[MX]; int solve(int pos) { if (pos > n) return 1e17; if (pos == n) return 0; if (dp[pos] != -1) return dp[pos]; int ans = 1e17, curr_height = v[pos], next_height; for (int i = 1; i <= k; i++) { if (pos + i <= n) { next_height = v[pos + i]; ans = min(ans, solve(pos + i) + abs(curr_height - next_height)); } } return dp[pos] = ans; } int32_t main() { memset(dp, -1, sizeof dp); cin >> n >> k; v.resize(n + 1); for (int i = 1; i <= n; i++) cin >> v[i]; cout << solve(1); return 0; }
[ "expression.operation.binary.add" ]
958,240
958,241
u543083821
cpp
p03161
#include <iostream> #define INF 1000001 using namespace std; int main() { int n = 0, k = 0, buf1 = 0; cin >> n >> k; int *dp = new int[n + 1]; dp[0] = 0; dp[1] = 0; int *h = new int[k + 1]; h[0] = INF; for (int i = 1; i < n + 1; ++i) { cin >> buf1; h[i] = buf1; } for (int i = 2; i < n + 1; ++i) { dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]); for (int j = 2; j < k + 1; ++j) { dp[i] = min(dp[i], dp[max(i - j, 0)] + abs(h[i] - h[max(i - j, 0)])); } } cout << dp[n]; delete[] dp; delete[] h; return 0; }
#include <iostream> #define INF 1000001 using namespace std; int main() { int n = 0, k = 0, buf1 = 0; cin >> n >> k; int *dp = new int[n + 1]; dp[0] = 0; dp[1] = 0; int *h = new int[n + 1]; h[0] = INF; for (int i = 1; i < n + 1; ++i) { cin >> buf1; h[i] = buf1; } for (int i = 2; i < n + 1; ++i) { dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]); for (int j = 2; j < k + 1; ++j) { dp[i] = min(dp[i], dp[max(i - j, 0)] + abs(h[i] - h[max(i - j, 0)])); } } cout << dp[n]; delete[] dp; delete[] h; return 0; }
[ "identifier.change", "expression.operation.binary.change" ]
958,254
958,255
u545767478
cpp
p03161
#include <bits/stdc++.h> using namespace std; int dp[100005]; int helper(int arr[], int i, int n, int k) { if (i == n - 1) { return 0; } if (dp[i] != -1) { return dp[i]; } int ans = 100000; for (int j = 1; j <= k; j++) { if (i + j < n) { ans = min(ans, helper(arr, i + j, n, k) + abs(arr[i + j] - arr[i])); } } return dp[i] = ans; } int main() { int n; cin >> n; int arr[n]; int k; cin >> k; for (int i = 0; i < n; i++) { cin >> arr[i]; } memset(dp, -1, sizeof(dp)); cout << helper(arr, 0, n, k) << endl; }
#include <bits/stdc++.h> using namespace std; int dp[100005]; int helper(int arr[], int i, int n, int k) { if (i == n - 1) { return 0; } if (dp[i] != -1) { return dp[i]; } int ans = 1e9; for (int j = 1; j <= k; j++) { if (i + j < n) { ans = min(ans, helper(arr, i + j, n, k) + abs(arr[i + j] - arr[i])); } } return dp[i] = ans; } int main() { int n; cin >> n; int arr[n]; int k; cin >> k; for (int i = 0; i < n; i++) { cin >> arr[i]; } memset(dp, -1, sizeof(dp)); cout << helper(arr, 0, n, k) << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
958,262
958,263
u214732904
cpp
p03161
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> h(N); for (int i = 0; i < N; i++) { cin >> h[i]; } vector<int> dp(N, 1e9 + 7); dp[0] = 0; for (int i = 1; i < N; i++) { for (int j = 1; j < K + 1; j++) { if (j - i < 0) break; dp[i] = min(dp[i], abs(h[i] - h[i - j]) + dp[i - j]); } } cout << dp[N - 1] << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> h(N); for (int i = 0; i < N; i++) { cin >> h[i]; } vector<int> dp(N, 1e9 + 7); dp[0] = 0; for (int i = 1; i < N; i++) { for (int j = 1; j < K + 1; j++) { if (i - j < 0) break; dp[i] = min(dp[i], abs(h[i] - h[i - j]) + dp[i - j]); } } cout << dp[N - 1] << endl; }
[ "control_flow.loop.for.condition.change", "expression.operation.binary.remove", "control_flow.branch.if.condition.change" ]
958,271
958,272
u832995587
cpp
p03161
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> h(N); for (int i = 0; i < N; i++) { cin >> h[i]; } vector<int> dp(N, 1e9 + 7); dp[0] = 0; for (int i = 1; i < N; i++) { for (int j = 1; j < K + 1; j++) { if (j - 1 < 0) break; dp[i] = min(dp[i], abs(h[i] - h[i - j]) + dp[i - j]); } } cout << dp[N - 1] << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> h(N); for (int i = 0; i < N; i++) { cin >> h[i]; } vector<int> dp(N, 1e9 + 7); dp[0] = 0; for (int i = 1; i < N; i++) { for (int j = 1; j < K + 1; j++) { if (i - j < 0) break; dp[i] = min(dp[i], abs(h[i] - h[i - j]) + dp[i - j]); } } cout << dp[N - 1] << endl; }
[ "identifier.change", "control_flow.branch.if.condition.change", "identifier.replace.add", "literal.replace.remove" ]
958,273
958,272
u832995587
cpp
p03161
#include <algorithm> #include <climits> #include <iostream> #include <vector> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> h(n); for (int i = 0; i < n; i++) cin >> h[i]; vector<int> d(n, LONG_MAX); d[0] = 0; for (int i = 1; i < n; i++) { for (int j = 0; j < k; j++) { if (i > j) d[i] = min(d[i], d[i - j - 1] + abs(h[i] - h[i - j - 1])); } } cout << d[n - 1] << endl; return 0; }
#include <algorithm> #include <climits> #include <iostream> #include <vector> using namespace std; int main() { long n, k; cin >> n >> k; vector<long> h(n); for (long i = 0; i < n; i++) cin >> h[i]; vector<long> d(n, LONG_MAX); d[0] = 0; for (long i = 1; i < n; i++) { for (long j = 0; j < k; j++) { if (i > j) d[i] = min(d[i], d[i - j - 1] + abs(h[i] - h[i - j - 1])); } } cout << d[n - 1] << endl; return 0; }
[ "variable_declaration.type.primitive.change", "control_flow.loop.for.initializer.change" ]
958,281
958,282
u812793098
cpp
p03161
// Created by:Coding_lover(17-06-2020 09:50:41) #include <bits/stdc++.h> #define ll long long #define FASTER \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define endl '\n' #define INF LLONG_MAX #define f first #define s second #define LB lower_bound #define UB upper_bound #define pi pair<long long, long long> #define pii pair<long long, pi> #define pb push_back #define all(v) v.begin(), v.end() #define sz(v) v.size() #define vc vector #define vll vector<long long> #define rep(i, a, n) for (ll i = a; i < (long long)n; ++i) #define repe(i, a, n) for (ll i = a; i <= (long long)n; ++i) #define repr(i, n, a) for (ll i = n; i > (long long)a; --i) #define repre(i, n, a) for (ll i = n; i >= (long long)a; --i) using namespace std; int main() { FASTER; ll t; t = 1; // cin >> t; while (t--) { ll n, k; cin >> n >> k; vll h(n); rep(i, 0, n) cin >> h[i]; vll dp(n, INF); dp[0] = h[0]; dp[1] = abs(h[0] - h[1]); rep(i, 0, n) { ll j = (i - k) >= 0 ? i - k : 0; for (; j <= i; j++) { dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j])); } // cout<<i<<" "<<dp[i]<<endl; } cout << dp[n - 1] << endl; } return 0; }
// Created by:Coding_lover(17-06-2020 09:50:41) #include <bits/stdc++.h> #define ll long long #define FASTER \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define endl '\n' #define INF LLONG_MAX #define f first #define s second #define LB lower_bound #define UB upper_bound #define pi pair<long long, long long> #define pii pair<long long, pi> #define pb push_back #define all(v) v.begin(), v.end() #define sz(v) v.size() #define vc vector #define vll vector<long long> #define rep(i, a, n) for (ll i = a; i < (long long)n; ++i) #define repe(i, a, n) for (ll i = a; i <= (long long)n; ++i) #define repr(i, n, a) for (ll i = n; i > (long long)a; --i) #define repre(i, n, a) for (ll i = n; i >= (long long)a; --i) using namespace std; int main() { FASTER; ll t; t = 1; // cin >> t; while (t--) { ll n, k; cin >> n >> k; vll h(n); rep(i, 0, n) cin >> h[i]; vll dp(n, INF); dp[0] = 0; dp[1] = abs(h[0] - h[1]); rep(i, 0, n) { ll j = (i - k) >= 0 ? i - k : 0; for (; j <= i; j++) { dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j])); } // cout<<i<<" "<<dp[i]<<endl; } cout << dp[n - 1] << endl; } return 0; }
[]
958,286
958,287
u408960947
cpp
p03161
#include <climits> #include <iostream> using namespace std; int min_cost(int height[], int n, int k) { int dp[n]; dp[0] = 0; for (int i = 2; i < n; i++) { dp[i] = INT_MAX; for (int j = 1; j <= k && (i - j >= 0); j++) { dp[i] = min(dp[i], dp[i - j] + abs(height[i] - height[i - j])); } } return dp[n - 1]; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; int height[n]; for (int i = 0; i < n; ++i) { cin >> height[i]; } cout << min_cost(height, n, k) << endl; return 0; }
#include <climits> #include <iostream> using namespace std; int min_cost(int height[], int n, int k) { int dp[n]; dp[0] = 0; for (int i = 1; i < n; i++) { dp[i] = INT_MAX; for (int j = 1; j <= k && (i - j >= 0); j++) { dp[i] = min(dp[i], dp[i - j] + abs(height[i] - height[i - j])); } } return dp[n - 1]; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; int height[n]; for (int i = 0; i < n; ++i) { cin >> height[i]; } cout << min_cost(height, n, k) << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
958,290
958,291
u959838921
cpp
p03161
#include <bits/stdc++.h> using namespace std; #define ll long long int min(ll a, ll b) { if (a < b) return a; return b; } int main() { ll n, k; cin >> n >> k; vector<ll> v(n, 0); int dp[100001]; for (int i = 0; i < 100001; i++) { dp[i] = INT_MAX; } dp[0] = 0; for (int i = 0; i < n; i++) { cin >> v[i]; } for (int i = 0; i < n; i++) { for (int j = i + 1; j <= k; j++) { if (j < n) { dp[j] = min(dp[j], dp[i] + abs(v[i] - v[j])); } } } cout << dp[n - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int min(ll a, ll b) { if (a < b) return a; return b; } int main() { ll n, k; cin >> n >> k; vector<ll> v(n, 0); int dp[100001]; for (int i = 0; i < 100001; i++) { dp[i] = INT_MAX; } dp[0] = 0; for (int i = 0; i < n; i++) { cin >> v[i]; } for (int i = 0; i < n; i++) { for (int j = i + 1; j <= i + k; j++) { if (j < n) { dp[j] = min(dp[j], dp[i] + abs(v[i] - v[j])); } } } cout << dp[n - 1] << endl; return 0; }
[ "control_flow.loop.for.condition.change" ]
958,292
958,293
u475972732
cpp
p03161
#include <bits/stdc++.h> using namespace std; int main() { int n, x, k; vector<int> v; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> x; v.push_back(x); } if (n == 1) return 0; vector<int> dp(n, 0); for (int i = n - 1; i >= 0; i--) { dp[i] = INT_MAX; for (int j = i + 1; j <= i + k && j < n; j++) { dp[i] = min(dp[i], abs(v[i] - v[j]) + dp[j]); } } cout << dp[0] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, x, k; vector<int> v; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> x; v.push_back(x); } if (n == 1) return 0; vector<int> dp(n, 0); for (int i = n - 2; i >= 0; i--) { dp[i] = INT_MAX; for (int j = i + 1; j <= i + k && j < n; j++) { dp[i] = min(dp[i], abs(v[i] - v[j]) + dp[j]); } } cout << dp[0] << endl; return 0; }
[ "literal.number.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "expression.operation.binary.change" ]
958,294
958,295
u845776743
cpp
p03161
#include <bits/stdc++.h> using namespace std; int main() { int n, x, k; vector<int> v; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> x; v.push_back(x); } if (n == 1) return 0; vector<int> dp(n, 0); for (int i = n - 1; i >= 0; i--) { dp[i] = INT_MAX; for (int j = i + 1; j <= i + k; j++) { dp[i] = min(dp[i], abs(v[i] - v[j]) + dp[j]); } } cout << dp[0] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, x, k; vector<int> v; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> x; v.push_back(x); } if (n == 1) return 0; vector<int> dp(n, 0); for (int i = n - 2; i >= 0; i--) { dp[i] = INT_MAX; for (int j = i + 1; j <= i + k && j < n; j++) { dp[i] = min(dp[i], abs(v[i] - v[j]) + dp[j]); } } cout << dp[0] << endl; return 0; }
[ "literal.number.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "expression.operation.binary.change", "control_flow.loop.for.condition.change" ]
958,296
958,295
u845776743
cpp
p03161
#include <bits/stdc++.h> #define input_vector(v, n) \ for (long long i = 0; i < n; i++) { \ cin >> v[i]; \ } #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define pb push_back using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; vector<ll> v(n); input_vector(v, n); vector<ll> dp(n); dp[0] = 0; for (ll i = 1; i < n; i++) { dp[i] = dp[i - 1] + abs(v[i - 1] - v[i]); for (int j = 2; j <= k && i - j >= 0; j++) { dp[i] = min(dp[i], dp[i - k] + abs(v[i] - v[i - j])); } } cout << dp[n - 1] << endl; return 0; }
#include <bits/stdc++.h> #define input_vector(v, n) \ for (long long i = 0; i < n; i++) { \ cin >> v[i]; \ } #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define pb push_back using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; vector<ll> v(n); input_vector(v, n); vector<ll> dp(n); dp[0] = 0; for (ll i = 1; i < n; i++) { dp[i] = dp[i - 1] + abs(v[i - 1] - v[i]); for (int j = 2; j <= k && i - j >= 0; j++) { dp[i] = min(dp[i], dp[i - j] + abs(v[i] - v[i - j])); } } cout << dp[n - 1] << endl; return 0; }
[ "assignment.value.change", "identifier.change", "variable_access.subscript.index.change", "call.arguments.change", "expression.operation.binary.change" ]
958,320
958,321
u249211191
cpp
p03161
#include <bits/stdc++.h> #define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++) #define all(v) v.begin(), v.end() using ll = long long; using namespace std; int main() { int n, k, h[100500]; cin >> n >> k; rep(i, n) cin >> h[i]; int cost[100500] = {}; for (int i = 1; i < 100000; i++) cost[i] = 20000; for (int i = 0; i < n; i++) { for (int j = 1; j <= k; j++) { cost[i + j] = min(cost[i + j], cost[i] + abs(h[i] - h[i + j])); } } cout << cost[n - 1]; }
#include <bits/stdc++.h> #define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++) #define all(v) v.begin(), v.end() using ll = long long; using namespace std; int main() { int n, k, h[100500]; cin >> n >> k; rep(i, n) cin >> h[i]; int cost[100500] = {}; for (int i = 1; i < 100500; i++) cost[i] = 1e9; for (int i = 0; i < n; i++) { for (int j = 1; j <= k; j++) { cost[i + j] = min(cost[i + j], cost[i] + abs(h[i] - h[i + j])); } } cout << cost[n - 1]; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "assignment.value.change" ]
958,322
958,323
u018372223
cpp
p03161
#include <bits/stdc++.h> using namespace std; #define FAST \ std::ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define M 1000000007 #define mp make_pair #define pb push_back #define PB pop_back #define sl(a) (int)a.length() #define sz(a) (int)a.size() #define lcase(a) (char)tolower(a) #define ucase(a) (char)toupper(a) #define precise(a) fixed << setprecision(a) << #define F first #define S second #define I insert #define pii pair<int, int> #define trav(a, x) for (auto &a : x) #define fl(i, n) for (int i = 0; i < n; i++) #define rfl(n) for (int i = n - 1; i >= 0; i--) #define time \ cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; #define invect(data, n, commands) \ for (int i = 0; i < n; i++) { \ int tmp; \ cin >> tmp; \ data.pb(tmp); \ commands \ } #define inset(data, n, commands) \ for (int i = 0; i < n; i++) { \ int tmp; \ cin >> tmp; \ data.I(tmp); \ commands \ } #define display(x) \ trav(a, x) cout << a << " "; \ cout << endl; #define ingrid(data, n, commands) \ for (int i = 0; i < n; i++) { \ cin >> data[i]; \ commands \ } #define section(a, b, w) \ set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(w)); #define union(a, b, w) \ set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(w)); #define copy(a, w) copy(a.begin(), a.end(), back_inserter(w)); #define all(data) data.begin(), data.end() #define PI 3.14159265358979323844 #define endl '\n' #define last(a) a[sz(a) - 1] #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { std::cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); std::cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } // Graph DFS const int fx[] = {+1, -1, +0, +0}; const int fy[] = {+0, +0, +1, -1}; // primes for hashing 937,991,1013,1409,1741 // Returns index of first element not less than key and more than key // respectively #define lb(data, key) lower_bound(all(data), key) - data.begin(); #define up(data, key) upper_bound(all(data), key) - data.begin(); #define fnd(data, key) find(all(data), key) - data.begin(); /* Long Long Int */ #define int long long int std::vector<int> v, a; int dp(int n, int k) { if (v[n] == -1) { std::vector<int> t; fl(i, k) { if (n + i >= v.size()) break; else t.pb(dp(n + i + 1, k) + abs(a[n + i + 1] - a[n])); } v[n] = *min_element(all(t)); } return v[n]; } void solve() { int n, k; cin >> n >> k; fl(i, n) { int j; cin >> j; a.pb(j); v.pb(-1); } v[v.size() - 1] = 0; v[v.size() - 2] = abs(a[n - 1] - a[n - 2]); int z = dp(0, k); cout << z; return; } signed main() { FAST int t = 1; // cin>>t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define FAST \ std::ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define M 1000000007 #define mp make_pair #define pb push_back #define PB pop_back #define sl(a) (int)a.length() #define sz(a) (int)a.size() #define lcase(a) (char)tolower(a) #define ucase(a) (char)toupper(a) #define precise(a) fixed << setprecision(a) << #define F first #define S second #define I insert #define pii pair<int, int> #define trav(a, x) for (auto &a : x) #define fl(i, n) for (int i = 0; i < n; i++) #define rfl(n) for (int i = n - 1; i >= 0; i--) #define time \ cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; #define invect(data, n, commands) \ for (int i = 0; i < n; i++) { \ int tmp; \ cin >> tmp; \ data.pb(tmp); \ commands \ } #define inset(data, n, commands) \ for (int i = 0; i < n; i++) { \ int tmp; \ cin >> tmp; \ data.I(tmp); \ commands \ } #define display(x) \ trav(a, x) cout << a << " "; \ cout << endl; #define ingrid(data, n, commands) \ for (int i = 0; i < n; i++) { \ cin >> data[i]; \ commands \ } #define section(a, b, w) \ set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(w)); #define union(a, b, w) \ set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(w)); #define copy(a, w) copy(a.begin(), a.end(), back_inserter(w)); #define all(data) data.begin(), data.end() #define PI 3.14159265358979323844 #define endl '\n' #define last(a) a[sz(a) - 1] #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { std::cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); std::cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } // Graph DFS const int fx[] = {+1, -1, +0, +0}; const int fy[] = {+0, +0, +1, -1}; // primes for hashing 937,991,1013,1409,1741 // Returns index of first element not less than key and more than key // respectively #define lb(data, key) lower_bound(all(data), key) - data.begin(); #define up(data, key) upper_bound(all(data), key) - data.begin(); #define fnd(data, key) find(all(data), key) - data.begin(); /* Long Long Int */ #define int long long int std::vector<int> v, a; int dp(int n, int k) { if (v[n] == -1) { std::vector<int> t; fl(i, k) { if (n + i + 1 >= v.size()) break; else t.pb(dp(n + i + 1, k) + abs(a[n + i + 1] - a[n])); } v[n] = *min_element(all(t)); } return v[n]; } void solve() { int n, k; cin >> n >> k; fl(i, n) { int j; cin >> j; a.pb(j); v.pb(-1); } v[v.size() - 1] = 0; v[v.size() - 2] = abs(a[n - 1] - a[n - 2]); int z = dp(0, k); cout << z; return; } signed main() { FAST int t = 1; // cin>>t; while (t--) solve(); return 0; }
[ "control_flow.branch.if.condition.change" ]
958,326
958,327
u386025735
cpp
p03161
#include <bits/stdc++.h> using namespace std; #define ll long long int ll f(int h[], int n, int k) { ll dp[n + 1] = {0}; dp[2] = abs(h[1] - h[0]); for (int i = 3; i <= n; i++) { ll inc = INT_MAX; for (int j = 1; j <= min(j, k); j++) { inc = min(inc, dp[i - j] + (ll)abs(h[i - 1] - h[i - j - 1])); } dp[i] += inc; } return dp[n]; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; int h[n]; for (int z = 0; z < n; z++) cin >> h[z]; cout << f(h, n, k); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int ll f(int h[], int n, int k) { ll dp[n + 1] = {0}; dp[2] = abs(h[1] - h[0]); for (int i = 3; i <= n; i++) { ll inc = INT_MAX; for (int j = 1; j <= min(i - 1, k); j++) { inc = min(inc, dp[i - j] + (ll)abs(h[i - 1] - h[i - j - 1])); } dp[i] += inc; } return dp[n]; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; int h[n]; for (int z = 0; z < n; z++) cin >> h[z]; cout << f(h, n, k); return 0; }
[ "control_flow.loop.for.condition.change", "call.arguments.change", "expression.operation.binary.change", "misc.off_by_one" ]
958,331
958,329
u803248534
cpp
p03161
#include <bits/stdc++.h> using namespace std; typedef long long ll; //マクロ // forループ関係 //引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか // Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define REPD(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++) #define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--) // xにはvectorなどのコンテナ #define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい #define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく #define MAX(x) *max_element(ALL(x)) //最大値を求める #define MIN(x) *min_element(ALL(x)) //最小値を求める //定数  #define INF 1000000000000 // 10^12:極めて大きい値,∞ #define INTINF 1000000000 #define MOD 10000007 // 10^9+7:合同式の法 #define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用) //略記 #define PB push_back // vectorヘの挿入 #define MP make_pair // pairのコンストラクタ #define F first // pairの一つ目の要素 #define S second // pairの二つ目の要素 #define N_MAX 100000 #define h_MAX 10000 #define K_MAX 100 int main() { int N; int K; long dp[N_MAX + 1]; int tmpdp; int mintmpdp; int h[N_MAX]; memset(dp, -1, sizeof(dp)); memset(h, -1, sizeof(h)); cin >> N; cin >> K; REP(i, N) { cin >> h[i]; } dp[0] = 0; dp[1] = abs(h[1] - h[0]); for (int i = 2; i < N; i++) { int jMax = min(i, K); mintmpdp = h_MAX; for (int j = 1; j <= jMax; j++) { tmpdp = dp[i - j] + abs(h[i] - h[i - j]); if (tmpdp < mintmpdp) { mintmpdp = tmpdp; } } dp[i] = mintmpdp; } cout << dp[N - 1]; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; //マクロ // forループ関係 //引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか // Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define REPD(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++) #define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--) // xにはvectorなどのコンテナ #define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい #define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく #define MAX(x) *max_element(ALL(x)) //最大値を求める #define MIN(x) *min_element(ALL(x)) //最小値を求める //定数  #define INF 1000000000000 // 10^12:極めて大きい値,∞ #define INTINF 1000000000 #define MOD 10000007 // 10^9+7:合同式の法 #define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用) //略記 #define PB push_back // vectorヘの挿入 #define MP make_pair // pairのコンストラクタ #define F first // pairの一つ目の要素 #define S second // pairの二つ目の要素 #define N_MAX 100000 #define h_MAX 10000 #define K_MAX 100 int main() { int N; int K; long dp[N_MAX + 1]; long tmpdp; long mintmpdp; int h[N_MAX]; memset(dp, -1, sizeof(dp)); memset(h, -1, sizeof(h)); cin >> N; cin >> K; REP(i, N) { cin >> h[i]; } dp[0] = 0; dp[1] = abs(h[1] - h[0]); for (int i = 2; i < N; i++) { int jMax = min(i, K); mintmpdp = h_MAX * N_MAX; for (int j = 1; j <= jMax; j++) { tmpdp = dp[i - j] + abs(h[i] - h[i - j]); if (tmpdp < mintmpdp) { mintmpdp = tmpdp; } } dp[i] = mintmpdp; } cout << dp[N - 1]; }
[ "variable_declaration.type.primitive.change", "assignment.change" ]
958,337
958,338
u675446829
cpp
p03161
#include <bits/stdc++.h> typedef long long int ll; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define p push #define p1 pop #define f first #define s second #define pb push_back #define mp make_pair #define pi pair<ll, ll> #define e 1000000007 using namespace std; ll dp[100002], arr[100002]; ll solve(ll n, ll k) { dp[1] = 0; for (int i = 2; i <= n; ++i) { ll ans = 100000; for (int j = max(ll(1), i - k); j <= i - 1; ++j) ans = min(ans, abs(arr[i] - arr[j]) + dp[j]); dp[i] = ans; } return dp[n]; } int main() { ll n, k; cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> arr[i]; cout << solve(n, k); }
#include <bits/stdc++.h> typedef long long int ll; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define p push #define p1 pop #define f first #define s second #define pb push_back #define mp make_pair #define pi pair<ll, ll> #define e 1000000007 using namespace std; ll dp[100002], arr[100002]; ll solve(ll n, ll k) { dp[1] = 0; for (int i = 2; i <= n; ++i) { ll ans = 10000000000000000; for (int j = max(ll(1), i - k); j <= i - 1; ++j) ans = min(ans, abs(arr[i] - arr[j]) + dp[j]); dp[i] = ans; } return dp[n]; } int main() { ll n, k; cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> arr[i]; cout << solve(n, k); }
[ "literal.number.change", "variable_declaration.value.change" ]
958,339
958,340
u607303480
cpp
p03161
#ifdef DEBUG #else #pragma GCC optimize("O3,no-stack-protector") #pragma GCC optimize("unroll-loops") #if __cplusplus < 201703L #pragma GCC target("avx") #else #pragma GCC target("avx2") #endif #endif #define _USE_MATH_DEFINES #include <bits/stdc++.h> #define dump(x) cout << x << endl typedef int64_t Int; typedef long double Ld; using namespace std; using Graph = vector<vector<Int>>; const Ld pi = M_PI; const Int MOD = 1000000007; Int Floor(Int a, Int b) { return (a - (a % b)) / b; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); const Int INF = 1 << 60; Int n, k; cin >> n >> k; vector<Int> h(n), dp(n + 105, INF); for (Int i = 0; i < n; i++) { cin >> h[i]; } dp[0] = 0; for (Int i = 0; i < n; i++) { for (Int j = 1; j <= k; j++) { if (0 <= i + j && i + j < n) { dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i])); } } } cout << dp[n - 1] << endl; return 0; }
#ifdef DEBUG #else #pragma GCC optimize("O3,no-stack-protector") #pragma GCC optimize("unroll-loops") #if __cplusplus < 201703L #pragma GCC target("avx") #else #pragma GCC target("avx2") #endif #endif #define _USE_MATH_DEFINES #include <bits/stdc++.h> #define dump(x) cout << x << endl typedef int64_t Int; typedef long double Ld; using namespace std; using Graph = vector<vector<Int>>; const Ld pi = M_PI; const Int MOD = 1000000007; Int Floor(Int a, Int b) { return (a - (a % b)) / b; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); const Int INF = 1LL << 60; Int n, k; cin >> n >> k; vector<Int> h(n), dp(n + 105, INF); for (Int i = 0; i < n; i++) { cin >> h[i]; } dp[0] = 0; for (Int i = 0; i < n; i++) { for (Int j = 1; j <= k; j++) { if (0 <= i + j && i + j < n) { dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i])); } } } cout << dp[n - 1] << endl; return 0; }
[ "literal.number.type.widen.change" ]
958,341
958,342
u261538386
cpp
p03161
#ifdef DEBUG #else #pragma GCC optimize("O3,no-stack-protector") #pragma GCC optimize("unroll-loops") #if __cplusplus < 201703L #pragma GCC target("avx") #else #pragma GCC target("avx2") #endif #endif #define _USE_MATH_DEFINES #include <bits/stdc++.h> #define dump(x) cout << x << endl typedef int64_t Int; typedef long double Ld; using namespace std; using Graph = vector<vector<Int>>; const Ld pi = M_PI; const Int MOD = 1000000007; Int Floor(Int a, Int b) { return (a - (a % b)) / b; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); const int INF = 1 << 29; Int n, k; cin >> n >> k; vector<Int> h(n), dp(n + 105, INF); for (Int i = 0; i < n; i++) { cin >> h[i]; } dp[0] = 0; for (Int i = 0; i < n; i++) { for (Int j = 1; j <= k; j++) { if (0 <= i + j && i + j < n) { dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i])); } } } cout << dp[n - 1] << endl; return 0; }
#ifdef DEBUG #else #pragma GCC optimize("O3,no-stack-protector") #pragma GCC optimize("unroll-loops") #if __cplusplus < 201703L #pragma GCC target("avx") #else #pragma GCC target("avx2") #endif #endif #define _USE_MATH_DEFINES #include <bits/stdc++.h> #define dump(x) cout << x << endl typedef int64_t Int; typedef long double Ld; using namespace std; using Graph = vector<vector<Int>>; const Ld pi = M_PI; const Int MOD = 1000000007; Int Floor(Int a, Int b) { return (a - (a % b)) / b; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); const Int INF = 1LL << 60; Int n, k; cin >> n >> k; vector<Int> h(n), dp(n + 105, INF); for (Int i = 0; i < n; i++) { cin >> h[i]; } dp[0] = 0; for (Int i = 0; i < n; i++) { for (Int j = 1; j <= k; j++) { if (0 <= i + j && i + j < n) { dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i])); } } } cout << dp[n - 1] << endl; return 0; }
[ "variable_declaration.type.change", "literal.number.type.widen.change", "literal.number.change", "expression.operation.binary.change" ]
958,343
958,342
u261538386
cpp
p03161
#include <bits/stdc++.h> using namespace std; /********************************************************************/ #define M1 1000000007 #define M3 1000000009 #define M2 998244353 #define ll long long #define pll pair<ll, ll> #define REP(i, a, b) for (ll i = a; i < b; i++) #define REPR(i, a, b) for (ll i = b - 1; i >= a; i--) #define forr(i, n) for (ll i = 0; i < n; i++) #define F first #define S second #define pb push_back #define DB pop_back #define mp make_pair #define MT make_tuple #define V(a) vector<a> #define vi vector<ll> #define endl '\n' #define ce(ele) cout << ele << ' ' #define cs(ele) cout << ele << '\n' #define CASE(t) \ ll t; \ cin >> t; \ while (t--) #define sor(v) sort(v.begin(), v.end()) #define rev(v) reverse(v.begin(), v.end()) /********************************************************************/ const double pi = 3.1415926535; ll n, m; const int mx = 69; char grid[mx][mx]; ll blocked[mx][mx]; ll vis[mx][mx]; /********************************************************************/ // FAST IO// void FAST() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } /********************************************************************/ ll power(ll a, ll b) { ll res = 1; for (int i = 1; i <= b; ++i) res *= a; return res; } ll sum(ll x) { ll ans = 0; while (x > 0) { ans += (x % 10); x /= 10; } return ans; } bool opp(int x, int y) { return ((x ^ y) < 0); } int main() { FAST(); ll n, k; cin >> n >> k; ll arr[n + 1], dp[n + 1]; for (ll i = 1; i <= n; i++) { cin >> arr[i]; } dp[1] = 0; for (ll i = 2; i <= n; i++) { dp[i] = 10000; } for (ll i = 1; i <= n; i++) { for (ll j = i + 1; j <= i + k && j <= n; j++) { dp[j] = min(dp[j], dp[i] + abs(arr[j] - arr[i])); // ce(dp[j]); } // cout<<endl; } cout << dp[n] << "\n"; }
#include <bits/stdc++.h> using namespace std; /********************************************************************/ #define M1 1000000007 #define M3 1000000009 #define M2 998244353 #define ll long long #define pll pair<ll, ll> #define REP(i, a, b) for (ll i = a; i < b; i++) #define REPR(i, a, b) for (ll i = b - 1; i >= a; i--) #define forr(i, n) for (ll i = 0; i < n; i++) #define F first #define S second #define pb push_back #define DB pop_back #define mp make_pair #define MT make_tuple #define V(a) vector<a> #define vi vector<ll> #define endl '\n' #define ce(ele) cout << ele << ' ' #define cs(ele) cout << ele << '\n' #define CASE(t) \ ll t; \ cin >> t; \ while (t--) #define sor(v) sort(v.begin(), v.end()) #define rev(v) reverse(v.begin(), v.end()) /********************************************************************/ const double pi = 3.1415926535; ll n, m; const int mx = 69; char grid[mx][mx]; ll blocked[mx][mx]; ll vis[mx][mx]; /********************************************************************/ // FAST IO// void FAST() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } /********************************************************************/ ll power(ll a, ll b) { ll res = 1; for (int i = 1; i <= b; ++i) res *= a; return res; } ll sum(ll x) { ll ans = 0; while (x > 0) { ans += (x % 10); x /= 10; } return ans; } bool opp(int x, int y) { return ((x ^ y) < 0); } int main() { FAST(); ll n, k; cin >> n >> k; ll arr[n + 1], dp[n + 1]; for (ll i = 1; i <= n; i++) { cin >> arr[i]; } dp[1] = 0; for (ll i = 2; i <= n; i++) { dp[i] = INT_MAX; } for (ll i = 1; i <= n; i++) { for (ll j = i + 1; j <= i + k && j <= n; j++) { dp[j] = min(dp[j], dp[i] + abs(arr[j] - arr[i])); // ce(dp[j]); } // cout<<endl; } cout << dp[n] << "\n"; }
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove" ]
958,351
958,350
u228592906
cpp
p03161
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int main() { ll n, k; cin >> n >> k; ll dp[100005]; ll h[100005]; for (int i = 0; i < n; i++) { cin >> h[i]; } for (int i = 0; i < n; i++) { dp[i] = -1; } dp[0] = 0; if (k == 1) { ll ans = 0; for (int i = 0; i < n - 1; i++) { ans += abs(h[i] - h[i + 1]); } cout << ans; return 0; } for (int i = 1; i < k; i++) { dp[i] = abs(h[i] - h[0]); } if (k >= n) { cout << abs(h[n - 1] - h[0]); return 0; } for (int i = k; i < n; i++) { for (int x = 1; x < k; x++) { ll temp = dp[i - x] + abs(h[i - x] - h[i]); if (dp[i] != -1) { dp[i] = min(dp[i], temp); } else { dp[i] = temp; } } } cout << dp[n - 1]; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int main() { ll n, k; cin >> n >> k; ll dp[100005]; ll h[100005]; for (int i = 0; i < n; i++) { cin >> h[i]; } for (int i = 0; i < n; i++) { dp[i] = -1; } dp[0] = 0; if (k == 1) { ll ans = 0; for (int i = 0; i < n - 1; i++) { ans += abs(h[i] - h[i + 1]); } cout << ans; return 0; } for (int i = 1; i < k; i++) { dp[i] = abs(h[i] - h[0]); } if (k >= n) { cout << abs(h[n - 1] - h[0]); return 0; } for (int i = k; i < n; i++) { for (int x = 1; x <= k; x++) { ll temp = dp[i - x] + abs(h[i - x] - h[i]); if (dp[i] != -1) { dp[i] = min(dp[i], temp); } else { dp[i] = temp; } } } cout << dp[n - 1]; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
958,352
958,353
u491044700
cpp
p03161
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { long n; long k; cin >> n; cin >> k; vector<long> nums(n); for (int i = 0; i < n; i++) { int x; cin >> x; nums[i] = x; } vector<long> dp(n, INT_MAX); dp[0] = 0; dp[1] = abs(nums[0] - nums[1]); for (long i = 2; i < n; i++) { for (long j = 1; i - j <= k && (i - j) > 0 && (i - j) < n; j++) dp[i] = min(dp[i], dp[i - j] + abs(nums[i] - nums[i - j])); } cout << dp[n - 1] << endl; return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { long n; long k; cin >> n; cin >> k; vector<long> nums(n); for (int i = 0; i < n; i++) { int x; cin >> x; nums[i] = x; } vector<long> dp(n, INT_MAX); dp[0] = 0; dp[1] = abs(nums[0] - nums[1]); for (long i = 2; i < n; i++) { for (long j = 1; j <= k && (i - j) >= 0 && (i - j) < n; j++) dp[i] = min(dp[i], dp[i - j] + abs(nums[i] - nums[i - j])); } cout << dp[n - 1] << endl; return 0; }
[ "control_flow.loop.for.condition.change", "expression.operation.binary.remove", "expression.operator.compare.change", "expression.operation.binary.change" ]
958,358
958,359
u038190565
cpp
p03161
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { long n; long k; cin >> n; cin >> k; vector<long> nums(n); for (int i = 0; i < n; i++) { int x; cin >> x; nums[i] = x; } vector<long> dp(n, INT_MAX); dp[0] = 0; dp[1] = abs(nums[0] - nums[1]); for (long i = 2; i < n; i++) { for (long j = 1; i - j <= k && (i - j) >= 0 && (i - j) < n; j++) dp[i] = min(dp[i], dp[i - j] + abs(nums[i] - nums[i - j])); } cout << dp[n - 1] << endl; return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { long n; long k; cin >> n; cin >> k; vector<long> nums(n); for (int i = 0; i < n; i++) { int x; cin >> x; nums[i] = x; } vector<long> dp(n, INT_MAX); dp[0] = 0; dp[1] = abs(nums[0] - nums[1]); for (long i = 2; i < n; i++) { for (long j = 1; j <= k && (i - j) >= 0 && (i - j) < n; j++) dp[i] = min(dp[i], dp[i - j] + abs(nums[i] - nums[i - j])); } cout << dp[n - 1] << endl; return 0; }
[ "control_flow.loop.for.condition.change", "expression.operation.binary.remove" ]
958,360
958,359
u038190565
cpp
p03161
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { long n; long k; cin >> n; cin >> k; vector<long> nums(n); for (int i = 0; i < n; i++) { int x; cin >> x; nums[i] = x; } vector<long> dp(n, INT_MAX); dp[0] = 0; dp[1] = abs(nums[0] - nums[1]); for (long i = 2; i < n; i++) { for (long j = 1; j < k && (i - j) > 0 && (i - j) < n; j++) dp[i] = min(dp[i], dp[i - j] + abs(nums[i] - nums[i - j])); } cout << dp[n - 1] << endl; return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { long n; long k; cin >> n; cin >> k; vector<long> nums(n); for (int i = 0; i < n; i++) { int x; cin >> x; nums[i] = x; } vector<long> dp(n, INT_MAX); dp[0] = 0; dp[1] = abs(nums[0] - nums[1]); for (long i = 2; i < n; i++) { for (long j = 1; j <= k && (i - j) >= 0 && (i - j) < n; j++) dp[i] = min(dp[i], dp[i - j] + abs(nums[i] - nums[i - j])); } cout << dp[n - 1] << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
958,361
958,359
u038190565
cpp
p03161
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { long n; long k; cin >> n; cin >> k; vector<long> nums(n); for (int i = 0; i < n; i++) { int x; cin >> x; nums[i] = x; } vector<long> dp(n, INT_MAX); dp[0] = 0; dp[1] = abs(nums[0] - nums[1]); for (long i = 2; i < n; i++) { for (long j = 1; j <= k && (i - j) > 0 && (i - j) < n; j++) dp[i] = min(dp[i], dp[i - j] + abs(nums[i] - nums[i - j])); } cout << dp[n - 1] << endl; return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { long n; long k; cin >> n; cin >> k; vector<long> nums(n); for (int i = 0; i < n; i++) { int x; cin >> x; nums[i] = x; } vector<long> dp(n, INT_MAX); dp[0] = 0; dp[1] = abs(nums[0] - nums[1]); for (long i = 2; i < n; i++) { for (long j = 1; j <= k && (i - j) >= 0 && (i - j) < n; j++) dp[i] = min(dp[i], dp[i - j] + abs(nums[i] - nums[i - j])); } cout << dp[n - 1] << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
958,362
958,359
u038190565
cpp
p03161
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { long n; long k; cin >> n; cin >> k; vector<long> nums(n); for (int i = 0; i < n; i++) { int x; cin >> x; nums[i] = x; } vector<long> dp(n, INT_MAX); dp[0] = 0; dp[1] = abs(nums[0] - nums[1]); for (long i = 2; i < n; i++) { for (long j = 1; j < k && (i - j) >= 0 && (i - j) < n; j++) dp[i] = min(dp[i], dp[i - j] + abs(nums[i] - nums[i - j])); } cout << dp[n - 1] << endl; return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { long n; long k; cin >> n; cin >> k; vector<long> nums(n); for (int i = 0; i < n; i++) { int x; cin >> x; nums[i] = x; } vector<long> dp(n, INT_MAX); dp[0] = 0; dp[1] = abs(nums[0] - nums[1]); for (long i = 2; i < n; i++) { for (long j = 1; j <= k && (i - j) >= 0 && (i - j) < n; j++) dp[i] = min(dp[i], dp[i - j] + abs(nums[i] - nums[i - j])); } cout << dp[n - 1] << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
958,363
958,359
u038190565
cpp
p03161
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { long n; long k; cin >> n; cin >> k; vector<long> nums(n); for (int i = 0; i < n; i++) { int x; cin >> x; nums[i] = x; } vector<long> dp(n, INT_MAX); dp[0] = 0; dp[1] = abs(nums[0] - nums[1]); for (long i = 2; i < n; i++) { for (long j = 1; j <= k && (i - j) >= 0 && (i - j) < n && i > j; j++) dp[i] = min(dp[i], dp[i - j] + abs(nums[i] - nums[i - j])); } cout << dp[n - 1] << endl; return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { long n; long k; cin >> n; cin >> k; vector<long> nums(n); for (int i = 0; i < n; i++) { int x; cin >> x; nums[i] = x; } vector<long> dp(n, INT_MAX); dp[0] = 0; dp[1] = abs(nums[0] - nums[1]); for (long i = 2; i < n; i++) { for (long j = 1; j <= k && (i - j) >= 0 && (i - j) < n; j++) dp[i] = min(dp[i], dp[i - j] + abs(nums[i] - nums[i - j])); } cout << dp[n - 1] << endl; return 0; }
[ "control_flow.loop.for.condition.change", "expression.operation.binary.remove" ]
958,364
958,359
u038190565
cpp
p03161
#include <bits/stdc++.h> using namespace std; long long n, h[1000200], dp[1000020], k; long long fun(long long n) { if (n <= 1) return 0; if (dp[n] != -1) return dp[n]; dp[n] = fun(n - 1) + abs(h[n - 1] - h[n]); for (long long x = n - 1; x >= n - k; x--) dp[n] = min(dp[n], fun(x) + abs(h[n] - h[x])); return dp[n]; } int main() { long long x, y, z, i, j; cin >> n >> k; memset(dp, -1, sizeof(dp)); for (x = 1; x <= n; x++) cin >> h[x]; long long ans = fun(n); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; long long n, h[1000200], dp[1000020], k; long long fun(long long n) { if (n <= 1) return 0; if (dp[n] != -1) return dp[n]; dp[n] = fun(n - 1) + abs(h[n - 1] - h[n]); for (long long x = n - 1; x >= n - k && x > 0; x--) dp[n] = min(dp[n], fun(x) + abs(h[n] - h[x])); return dp[n]; } int main() { long long x, y, z, i, j; cin >> n >> k; memset(dp, -1, sizeof(dp)); for (x = 1; x <= n; x++) cin >> h[x]; long long ans = fun(n); cout << ans << endl; }
[ "control_flow.loop.for.condition.change" ]
958,365
958,366
u152986325
cpp
p03161
#include <bits/stdc++.h> using namespace std; long long n, h[100020], dp[100020], k; long long fun(long long n) { if (n <= 1) return 0; if (dp[n] != -1) return dp[n]; dp[n] = fun(n - 1) + abs(h[n - 1] - h[n]); for (long long x = n - 1; x >= n - k; x--) dp[n] = min(dp[n], fun(x) + abs(h[n] - h[x])); return dp[n]; } int main() { long long x, y, z, i, j; cin >> n >> k; memset(dp, -1, sizeof(dp)); for (x = 1; x <= n; x++) cin >> h[x]; long long ans = fun(n); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; long long n, h[1000200], dp[1000020], k; long long fun(long long n) { if (n <= 1) return 0; if (dp[n] != -1) return dp[n]; dp[n] = fun(n - 1) + abs(h[n - 1] - h[n]); for (long long x = n - 1; x >= n - k && x > 0; x--) dp[n] = min(dp[n], fun(x) + abs(h[n] - h[x])); return dp[n]; } int main() { long long x, y, z, i, j; cin >> n >> k; memset(dp, -1, sizeof(dp)); for (x = 1; x <= n; x++) cin >> h[x]; long long ans = fun(n); cout << ans << endl; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "control_flow.loop.for.condition.change" ]
958,367
958,366
u152986325
cpp
p03161
using namespace std; #include <bits/stdc++.h> #define ll long long int #define ull unsigned long long int #define INFINITE 1e9 + 5 #define MOD 1000000007 #define MAXN 100001 #define pll pair<ll, ll> #define pii pair<int, int> int dp[MAXN]; int arr[MAXN]; int num, m; int func(int ind) { if (ind == num) { return 0; } if (dp[ind] != -1) { return dp[ind]; } int mini = INFINITE; for (int i = ind + 1; i <= min(num, ind + m); i++) { mini = min(mini, (arr[i] - arr[ind])) + func(i + 1); } return dp[ind] = mini; } int main() { memset(dp, -1, sizeof(dp)); cin >> num >> m; for (int i = 1; i <= num; i++) { cin >> arr[i]; } cout << func(1); }
using namespace std; #include <bits/stdc++.h> #define ll long long int #define ull unsigned long long int #define INFINITE 1e9 + 5 #define MOD 1000000007 #define MAXN 100001 #define pll pair<ll, ll> #define pii pair<int, int> int dp[MAXN]; int arr[MAXN]; int num, m; int func(int ind) { if (ind == num) { return 0; } if (dp[ind] != -1) { return dp[ind]; } int mini = INFINITE; for (int i = ind + 1; i <= min(num, ind + m); i++) { mini = min(mini, abs(arr[i] - arr[ind]) + func(i)); } return dp[ind] = mini; } int main() { memset(dp, -1, sizeof(dp)); cin >> num >> m; for (int i = 1; i <= num; i++) { cin >> arr[i]; } cout << func(1); }
[ "call.add", "call.arguments.change", "assignment.value.change", "expression.operation.binary.change" ]
958,368
958,369
u836655051
cpp
p03161
///=======================/// /// coder: Andy - Tohrumi /// ///=======================/// #include <bits/stdc++.h> #define ll long long #define ld long double #define fastio \ ios_base::sync_with_stdio(); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define rep(i, a, b) for (__typeof(b) i = a; i < b; i++) #define Rep(i, a, b) for (__typeof(a) i = a; i > b; i--) using namespace std; typedef pair<ll, ll> pll; typedef pair<int, int> ii; typedef vector<pll> vll; typedef vector<string> vs; typedef vector<ii> vii; typedef vector<int> vi; typedef vector<ll> vl; ///======code start here======/// signed main() { fastio; int n, k; cin >> n >> k; ll h[n + 1]; h[0] = 12345678901234567; rep(i, 1, n + 1) cin >> h[i]; ll dp[n + 1]; dp[2] = 0; dp[1] = 0; rep(i, 2, n + 1) dp[i] = 12345678901234567; rep(i, 2, n + 1) { rep(j, 1, k + 1) { dp[i] = min(dp[i - j] + abs(h[max(i - j, 0)] - h[i]), dp[i]); } } cout << dp[n] << endl; return 0; }
///=======================/// /// coder: Andy - Tohrumi /// ///=======================/// #include <bits/stdc++.h> #define ll long long #define ld long double #define fastio \ ios_base::sync_with_stdio(); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define rep(i, a, b) for (__typeof(b) i = a; i < b; i++) #define Rep(i, a, b) for (__typeof(a) i = a; i > b; i--) using namespace std; typedef pair<ll, ll> pll; typedef pair<int, int> ii; typedef vector<pll> vll; typedef vector<string> vs; typedef vector<ii> vii; typedef vector<int> vi; typedef vector<ll> vl; ///======code start here======/// signed main() { fastio; int n, k; cin >> n >> k; ll h[n + 1]; h[0] = 12345678901234567; rep(i, 1, n + 1) cin >> h[i]; ll dp[n + 1]; dp[0] = 0; dp[1] = 0; rep(i, 2, n + 1) dp[i] = 12345678901234567; rep(i, 2, n + 1) { rep(j, 1, k + 1) { dp[i] = min(dp[max(i - j, 0)] + abs(h[max(i - j, 0)] - h[i]), dp[i]); } } cout << dp[n] << endl; return 0; }
[ "literal.number.change", "assignment.variable.change", "variable_access.subscript.index.change", "call.add", "call.arguments.add" ]
958,370
958,371
u340424586
cpp
p03161
#include <bits/stdc++.h> #include <sstream> #define F first #define S second #define PB push_back #define MP make_pair #define rep(i, a, b) for (ll i = a; i <= b; ++i) #define fo(i, a, b) for (int i = a; i <= b; ++i) #define ull unsigned long long int #define ll long long #define all(a) a.begin(), a.end() using namespace std; typedef vector<ll> vi; typedef pair<ll, ll> pi; ll MD = 1000000007; ll md = 998244353; ll exp(ll a, ll b) { ll r = 1ll; while (b > 0) { if (b & 1) { r = r * (a % md); r = (r + md) % md; } b /= 2; a = (a % md) * (a % md); a = (a + md) % md; } return (r + md) % md; } // put b as bmod(md-1) if md is prime} ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll pow_2(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a); a = (a * a); b >>= 1; } return res; } bool isPrime(ll a) { for (ll i = 3; (i * i) <= a; i += 2) { if ((a % i) == 0) return false; } if ((a != 2) && ((a % 2) == 0)) return false; if (a == 1) return false; return true; } string decToBinary(int n) { // Size of an integer is assumed to be 32 bits string s = ""; for (int i = 31; i >= 0; i--) { int k = n >> i; if (k & 1) // cout << "1"; s = s + "1"; else // cout << "0"; s = s + "0"; } return s; } int decimalToBinary(int N) { // To store the binary number ull B_Number = 0; int cnt = 0; while (N != 0) { int rem = N % 2; ull c = pow(10, cnt); B_Number += rem * c; N /= 2; // Count used to store exponent value cnt++; } return B_Number; } string toString(ull num) { std::string number; std::stringstream strstream; strstream << num; strstream >> number; return number; } const double PI = acos(-1); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; int h[n]; fo(i, 0, n - 1) cin >> h[i]; int dp[n]; dp[0] = 0; dp[1] = abs(h[1] - h[0]); for (int i = 2; i < n; i++) dp[i] = MD; for (int i = 2; i < n; i++) { for (int j = 1; j <= min(i, k); j++) { dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j])); } } cout << dp[n - 1] << endl; return 0; }
#include <bits/stdc++.h> #include <sstream> #define F first #define S second #define PB push_back #define MP make_pair #define rep(i, a, b) for (ll i = a; i <= b; ++i) #define fo(i, a, b) for (int i = a; i <= b; ++i) #define ull unsigned long long int #define ll long long #define all(a) a.begin(), a.end() using namespace std; typedef vector<ll> vi; typedef pair<ll, ll> pi; ll MD = 1000000007; ll md = 998244353; ll exp(ll a, ll b) { ll r = 1ll; while (b > 0) { if (b & 1) { r = r * (a % md); r = (r + md) % md; } b /= 2; a = (a % md) * (a % md); a = (a + md) % md; } return (r + md) % md; } // put b as bmod(md-1) if md is prime} ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll pow_2(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a); a = (a * a); b >>= 1; } return res; } bool isPrime(ll a) { for (ll i = 3; (i * i) <= a; i += 2) { if ((a % i) == 0) return false; } if ((a != 2) && ((a % 2) == 0)) return false; if (a == 1) return false; return true; } string decToBinary(int n) { // Size of an integer is assumed to be 32 bits string s = ""; for (int i = 31; i >= 0; i--) { int k = n >> i; if (k & 1) // cout << "1"; s = s + "1"; else // cout << "0"; s = s + "0"; } return s; } int decimalToBinary(int N) { // To store the binary number ull B_Number = 0; int cnt = 0; while (N != 0) { int rem = N % 2; ull c = pow(10, cnt); B_Number += rem * c; N /= 2; // Count used to store exponent value cnt++; } return B_Number; } string toString(ull num) { std::string number; std::stringstream strstream; strstream << num; strstream >> number; return number; } const double PI = acos(-1); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; int h[n]; fo(i, 0, n - 1) cin >> h[i]; int dp[n]; dp[0] = 0; dp[1] = abs(h[1] - h[0]); for (int i = 2; i < n; i++) dp[i] = MD; for (int i = 2; i < n; i++) { for (int j = 0; j <= min(i, k); j++) { dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j])); } } cout << dp[n - 1] << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "assignment.change" ]
958,376
958,377
u513210134
cpp
p03161
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n; cin >> n; ll k; cin >> k; ll a[n + 1]; for (ll i = 1; i <= n; i++) { cin >> a[i]; } ll dp[n + 1]; for (ll i = 0; i <= n; i++) { dp[i] = 0; } dp[1] = 0; for (ll i = 2; i <= n; i++) { dp[i] = 10000; for (int j = i - 1; j >= max(1ll, i - k); j--) { dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j])); } } cout << dp[n] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n; cin >> n; ll k; cin >> k; ll a[n + 1]; for (ll i = 1; i <= n; i++) { cin >> a[i]; } ll dp[n + 1]; for (ll i = 0; i <= n; i++) { dp[i] = 0; } dp[1] = 0; for (ll i = 2; i <= n; i++) { dp[i] = LLONG_MAX; for (int j = i - 1; j >= max(1ll, i - k); j--) { dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j])); } } cout << dp[n] << endl; return 0; }
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove" ]
958,378
958,379
u288901204
cpp
p03161
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n; cin >> n; ll k; cin >> k; ll a[n + 1]; for (ll i = 1; i <= n; i++) { cin >> a[i]; } ll dp[n + 1]; for (ll i = 0; i <= n; i++) { dp[i] = 0; } dp[1] = 0; for (ll i = 2; i <= n; i++) { dp[i] = 10000; for (int j = i - 1; j >= max(1ll, i - k); j--) { dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j])); } } cout << dp[n] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n; cin >> n; ll k; cin >> k; ll a[n + 1]; for (ll i = 1; i <= n; i++) { cin >> a[i]; } ll dp[n + 1]; for (ll i = 0; i <= n; i++) { dp[i] = 0; } dp[1] = 0; for (ll i = 2; i <= n; i++) { dp[i] = LLONG_MAX; for (int j = i - 1; j >= max(1ll, i - k); j--) { dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j])); } } cout << dp[n] << endl; return 0; }
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove" ]
958,380
958,379
u288901204
cpp
p03161
#include <cmath> #include <iostream> #include <stdio.h> #include <string> #include <vector> using namespace std; int main() { long int N, K; cin >> N >> K; int h[N], cost[N]; for (int i = 0; i < N; i++) { cin >> h[i]; } cost[0] = 0; cost[1] = abs(h[1] - h[0]); for (int j = 2; j < N; j++) { cost[j] = cost[j - 1] + abs(h[j] - h[j - 1]); for (int k = 2; k <= K; k++) { if (cost[j] > cost[j - k] + abs(h[j] - h[j - k])) cost[j] = cost[j - k] + abs(h[j] - h[j - k]); } } cout << cost[N - 1] << endl; return 0; }
#include <cmath> #include <iostream> #include <stdio.h> #include <string> #include <vector> using namespace std; int main() { int N, K; cin >> N >> K; int h[N], cost[N]; for (int i = 0; i < N; i++) { cin >> h[i]; } cost[0] = 0; cost[1] = abs(h[1] - h[0]); for (int j = 2; j < N; j++) { cost[j] = cost[j - 1] + abs(h[j] - h[j - 1]); for (int k = 2; k <= min(j, K); k++) { if (cost[j] > cost[j - k] + abs(h[j] - h[j - k])) cost[j] = cost[j - k] + abs(h[j] - h[j - k]); } } cout << cost[N - 1] << endl; return 0; }
[ "variable_declaration.type.narrow.change", "control_flow.loop.for.condition.change", "call.add", "call.arguments.change" ]
958,386
958,387
u214864255
cpp