problem_id
stringlengths 6
6
| language
stringclasses 2
values | original_status
stringclasses 3
values | original_src
stringlengths 19
243k
| changed_src
stringlengths 19
243k
| change
stringclasses 3
values | i1
int64 0
8.44k
| i2
int64 0
8.44k
| j1
int64 0
8.44k
| j2
int64 0
8.44k
| error
stringclasses 270
values | stderr
stringlengths 0
226k
|
---|---|---|---|---|---|---|---|---|---|---|---|
p03160
|
C++
|
Runtime Error
|
// by rko27
// One more....
//---------------------------------------------------------------------------------------------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define fe first
#define se second
#define nl "\n"
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define god \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
//----------------------------------------------------------------------------------------------------------------------------------------------------
int mod = 1000000000 + 7;
int modu = 998244353;
//----------------------------------------------------------------------------------------------------------------------------------------------------
ll power(ll x, ll y) {
ll res = 1;
x = x;
while (y > 0) {
if (y & 1)
res = (res * x);
y = y >> 1;
x = (x * x);
}
return res;
}
ll powe(ll x, ll y) {
x = x % mod, y = y % (mod - 1);
ll ans = 1;
while (y > 0) {
if (y & 1) {
ans = (1ll * x * ans) % mod;
}
y >>= 1;
x = (1ll * x * x) % mod;
}
return ans;
}
void fun() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
// 786
}
bool isPrime(int n) {
for (int i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
ll ncr(ll n, ll r) {
ll res = 1;
if (r > n)
return 0;
if (r > n - r)
r = n - r;
for (ll i = 0; i < r; i++) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------
std::vector<pair<int, int>> v;
//--------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------
signed main() {
god;
// rko;
fun();
int tt = 1; // cin>>tt;
while (tt--) {
int n;
cin >> n;
int h[n + 1];
h[0] = 0;
for (int i = 1; i <= n; i++)
cin >> h[i];
int dp[n + 1];
dp[0] = 0;
dp[1] = 0;
dp[2] = abs(h[1] - h[2]);
for (int i = 3; i <= n; i++)
dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]),
dp[i - 1] + abs(h[i] - h[i - 1]));
cout << dp[n];
}
return 0;
}
|
// by rko27
// One more....
//---------------------------------------------------------------------------------------------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define fe first
#define se second
#define nl "\n"
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define god \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
//----------------------------------------------------------------------------------------------------------------------------------------------------
int mod = 1000000000 + 7;
int modu = 998244353;
//----------------------------------------------------------------------------------------------------------------------------------------------------
ll power(ll x, ll y) {
ll res = 1;
x = x;
while (y > 0) {
if (y & 1)
res = (res * x);
y = y >> 1;
x = (x * x);
}
return res;
}
ll powe(ll x, ll y) {
x = x % mod, y = y % (mod - 1);
ll ans = 1;
while (y > 0) {
if (y & 1) {
ans = (1ll * x * ans) % mod;
}
y >>= 1;
x = (1ll * x * x) % mod;
}
return ans;
}
void fun() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
// 786
}
bool isPrime(int n) {
for (int i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
ll ncr(ll n, ll r) {
ll res = 1;
if (r > n)
return 0;
if (r > n - r)
r = n - r;
for (ll i = 0; i < r; i++) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------
std::vector<pair<int, int>> v;
//--------------------------------------------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------------
signed main() {
god;
// rko;
fun();
int tt = 1; // cin>>tt;
while (tt--) {
int n;
cin >> n;
int h[n + 1];
h[0] = 0;
for (int i = 1; i <= n; i++)
cin >> h[i];
int dp[n + 1];
dp[0] = 0;
dp[1] = 0;
dp[2] = abs(h[1] - h[2]);
for (int i = 3; i <= n; i++)
dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]),
dp[i - 1] + abs(h[i] - h[i - 1]));
cout << dp[n];
}
return 0;
}
|
replace
| 52 | 56 | 52 | 56 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <math.h>
#include <utility>
using namespace std;
typedef long long ll;
ll dp[1000];
ll arr[1000];
int n = 0;
ll dpfun(int i) {
if (dp[i] != -1)
return dp[i];
if (i == n - 1)
return dp[i] = 0;
if (i == n - 2)
return dp[i] = abs(arr[i] - arr[i + 1]);
else
return dp[i] = min(abs(arr[i] - arr[i + 1]) + dpfun(i + 1),
abs(arr[i] - arr[i + 2]) + dpfun(i + 2));
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
memset(dp, -1, sizeof dp);
int i;
for (i = 0; i < n; i++)
cin >> arr[i];
cout << dpfun(0) << endl;
return 0;
}
|
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <math.h>
#include <utility>
using namespace std;
typedef long long ll;
ll dp[100005];
ll arr[100005];
int n = 0;
ll dpfun(int i) {
if (dp[i] != -1)
return dp[i];
if (i == n - 1)
return dp[i] = 0;
if (i == n - 2)
return dp[i] = abs(arr[i] - arr[i + 1]);
else
return dp[i] = min(abs(arr[i] - arr[i + 1]) + dpfun(i + 1),
abs(arr[i] - arr[i + 2]) + dpfun(i + 2));
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
memset(dp, -1, sizeof dp);
int i;
for (i = 0; i < n; i++)
cin >> arr[i];
cout << dpfun(0) << endl;
return 0;
}
|
replace
| 9 | 11 | 9 | 11 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main(void) {
int N;
cin >> N;
ll h[N];
ll dp[N];
for (int i = 1; i <= N; i++) {
cin >> h[i];
}
for (int i = 1; i <= N; i++) {
dp[i] = INF;
}
dp[1] = 0;
for (int i = 1; i <= N; i++) {
chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
}
cout << dp[N] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main(void) {
int N;
cin >> N;
ll h[100010];
ll dp[100010];
for (int i = 1; i <= N; i++) {
cin >> h[i];
}
for (int i = 1; i <= N; i++) {
dp[i] = INF;
}
dp[1] = 0;
for (int i = 1; i <= N; i++) {
chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
}
cout << dp[N] << endl;
}
|
replace
| 17 | 19 | 17 | 19 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
const int mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int dp[10010];
int main() {
int n;
cin >> n;
int h[n];
for (int i = 0; i < n; i++) {
cin >> h[i];
}
dp[0] = 0;
dp[1] = abs(h[1] - h[0]);
for (int i = 0; i < n - 2; i++) {
dp[i + 2] =
min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 1] + abs(h[i + 2] - h[i + 1]));
}
cout << dp[n - 1] << endl;
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
const int mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int dp[100100];
int main() {
int n;
cin >> n;
int h[n];
for (int i = 0; i < n; i++) {
cin >> h[i];
}
dp[0] = 0;
dp[1] = abs(h[1] - h[0]);
for (int i = 0; i < n - 2; i++) {
dp[i + 2] =
min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 1] + abs(h[i + 2] - h[i + 1]));
}
cout << dp[n - 1] << endl;
}
|
replace
| 16 | 17 | 16 | 17 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> h(n);
for (int i = 0; i < n; i++) {
cin >> h[i];
}
// i番目に到達するために必要なコストの最小値をdp[i]とする。
int dp[10010];
// dpテーブルの初期化
dp[0] = 0;
dp[1] = 0;
dp[2] = abs(h[1] - h[0]);
for (int i = 2; i < n; i++) {
dp[i + 1] =
min(dp[i] + abs(h[i] - h[i - 1]), dp[i - 1] + abs(h[i] - h[i - 2]));
}
cout << dp[n] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> h(n);
for (int i = 0; i < n; i++) {
cin >> h[i];
}
// i番目に到達するために必要なコストの最小値をdp[i]とする。
int dp[n];
// dpテーブルの初期化
dp[0] = 0;
dp[1] = 0;
dp[2] = abs(h[1] - h[0]);
for (int i = 2; i < n; i++) {
dp[i + 1] =
min(dp[i] + abs(h[i] - h[i - 1]), dp[i - 1] + abs(h[i] - h[i - 2]));
}
cout << dp[n] << endl;
}
|
replace
| 12 | 13 | 12 | 13 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long int
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#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];
#define w(x) \
int x; \
cin >> x; \
while (x--)
#define from(i, n) for (int i = 0; i < (int)n; i++)
#define from_j(i, j, n) for (int i = j; i < (int)n; i++)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
c_p_c();
int n;
cin >> n;
int arr[n];
from(i, n) cin >> arr[i];
int cost[n];
cost[0] = 0;
cost[1] = abs(arr[1] - arr[0]);
for (int i = 2; i < n; i++) {
cost[i] = min(cost[i - 1] + abs(arr[i] - arr[i - 1]),
cost[i - 2] + abs(arr[i] - arr[i - 2]));
}
cout << cost[n - 1];
return 0;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long int
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#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];
#define w(x) \
int x; \
cin >> x; \
while (x--)
#define from(i, n) for (int i = 0; i < (int)n; i++)
#define from_j(i, j, n) for (int i = j; i < (int)n; i++)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int32_t main() {
c_p_c();
int n;
cin >> n;
int arr[n];
from(i, n) cin >> arr[i];
int cost[n];
cost[0] = 0;
cost[1] = abs(arr[1] - arr[0]);
for (int i = 2; i < n; i++) {
cost[i] = min(cost[i - 1] + abs(arr[i] - arr[i - 1]),
cost[i - 2] + abs(arr[i] - arr[i - 2]));
}
cout << cost[n - 1];
return 0;
}
|
delete
| 37 | 41 | 37 | 37 |
-11
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long
int n, x, dp[10001];
vector<int> a;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n && cin >> x; i++)
a.push_back(x);
dp[1] = abs(a[1] - a[0]);
for (int i = 2; i < n; i++)
dp[i] =
min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
cout << dp[n - 1] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long
int n, x, dp[100001];
vector<int> a;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n && cin >> x; i++)
a.push_back(x);
dp[1] = abs(a[1] - a[0]);
for (int i = 2; i < n; i++)
dp[i] =
min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
cout << dp[n - 1] << endl;
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;
signed main() {
int n;
cin >> n;
vector<int> h(n + 1);
rep(i, n) cin >> h[i + 1];
vector<int> dp(10010, INF);
dp[0] = 0;
dp[1] = 0;
dp[2] = abs(h[2] - h[1]);
for (int i = 1; i < n - 1; i++) {
chmin(dp[i + 2], dp[i + 1] + abs(h[i + 2] - h[i + 1]));
chmin(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
}
// for(int i=1; i<=n; i++) cout<<dp[i]<<' ';
cout << dp[n] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;
signed main() {
int n;
cin >> n;
vector<int> h(n + 1);
rep(i, n) cin >> h[i + 1];
vector<int> dp(100100, INF);
dp[0] = 0;
dp[1] = 0;
dp[2] = abs(h[2] - h[1]);
for (int i = 1; i < n - 1; i++) {
chmin(dp[i + 2], dp[i + 1] + abs(h[i + 2] - h[i + 1]));
chmin(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
}
// for(int i=1; i<=n; i++) cout<<dp[i]<<' ';
cout << dp[n] << endl;
}
|
replace
| 36 | 37 | 36 | 37 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <cstdlib>
#include <vector>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const long long INF = 1LL << 60;
const int MAX = 10000;
long long h[MAX], dp[MAX];
void solve() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> h[i];
dp[i] = INF;
}
dp[0] = 0;
dp[1] = abs(h[1] - h[0]);
for (int i = 0; i < N - 1; i++) {
// dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
if (i != N - 2)
chmin(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
chmin(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
// chmin(dp[i], dp[i-1] + abs(h[i]-h[i-1]));
// chmin(dp[i], dp[i-2] + abs(h[i]-h[i-2]));
}
cout << dp[N - 1] << endl;
return;
}
int main() {
solve();
return 0;
}
|
#include <bits/stdc++.h>
#include <cstdlib>
#include <vector>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const long long INF = 1LL << 60;
const int MAX = 100000;
long long h[MAX], dp[MAX];
void solve() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> h[i];
dp[i] = INF;
}
dp[0] = 0;
dp[1] = abs(h[1] - h[0]);
for (int i = 0; i < N - 1; i++) {
// dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
if (i != N - 2)
chmin(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
chmin(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
// chmin(dp[i], dp[i-1] + abs(h[i]-h[i-1]));
// chmin(dp[i], dp[i-2] + abs(h[i]-h[i-2]));
}
cout << dp[N - 1] << endl;
return;
}
int main() {
solve();
return 0;
}
|
replace
| 22 | 23 | 22 | 23 |
0
| |
p03160
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0);
int main() {
IOS;
int n;
cin >> n;
int dp[n];
vector<int> H;
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
H.push_back(temp);
}
bool change = true;
for (int i = 1; i < n; i++) {
dp[i] = abs(H[i] - H[i - 1]) + dp[i - 1];
}
while (change) {
change = false;
for (int i = 2; i < n; i++) {
int t = abs(H[i] - H[i - 2]) + dp[i - 2];
if (t < dp[i]) {
dp[i] = t;
change = true;
}
}
if (!change)
break;
for (int i = 1; i < n; i++) {
int t = abs(H[i] - H[i - 1]) + dp[i - 1];
if (t < dp[i]) {
dp[i] = t;
change = true;
}
}
}
cout << dp[n - 1];
}
|
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0);
int main() {
IOS;
int n;
cin >> n;
int dp[n];
vector<int> H;
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
H.push_back(temp);
}
bool change = true;
dp[1] = abs(H[1] - H[0]) + dp[0];
for (int i = 2; i < n; i++) {
dp[i] =
min(abs(H[i] - H[i - 1]) + dp[i - 1], abs(H[i] - H[i - 2]) + dp[i - 2]);
} /*
int flag=0;
while(change)
{
change= false;
for(int i=2;i<n;i++)
{
int t=abs(H[i]-H[i-2])+dp[i-2];
if(t<dp[i])
{
dp[i]= t;
change= true;
}
}
if(!change)
break;
for(int i=1;i<n;i++)
{
int t=abs(H[i]-H[i-1])+dp[i-1];
if(t<dp[i])
{
dp[i]= t;
change= true;
}
}
}*/
cout << dp[n - 1];
}
|
replace
| 16 | 38 | 16 | 46 |
TLE
| |
p03160
|
C++
|
Runtime Error
|
// *
// *
// * Created By :hozaifa wahid
// * "mai maut ko takia aur kafan ko chadar banakar sota hu"
// *------------------------------------
// * OS : Ubuntu 16.04
// * Language : CPP14
// * Editor : Sublime Text 3
// * C++ compiler : g++
// *
// *
// https://www.geeksforgeeks.org/find-the-point-where-maximum-intervals-overlap/
#include <bits/stdc++.h>
#define pb push_back
// #define mp make_pair
#define inf 1000000007
#define fr first
#define sc second
#define eps 1e-9
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define sni(x) scanf("%d", &x)
#define snl(x) scanf("%lld", &x)
#define snc(x) scanf("%c", &c);
#define rep(n) for (int i = 0; i < n; i++)
#define repc(i, n) for (int i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
ll MOD = 1000000007;
vector<ll> v[100055];
void sieve() {
for (int n = 1; n <= 100055; n++) {
for (int i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
// If divisors are equal, print only one
if (n / i == i)
v[n].push_back(i);
else // Otherwise print both
{
v[n].push_back(i);
v[n].push_back(n / i);
}
}
}
}
}
ll pw(ll a, ll b) {
if (b == 0)
return 1;
ll x = pw(a, b / 2);
x = (x * x) % MOD;
if (b % 2)
x = (x * a) % MOD;
return x;
}
ll n, s;
ll a[100005];
int ok = 0;
// ll res=0;
ll dp[100005];
ll go(ll i) {
if (i == n - 1) {
return 0;
} else if (i == n - 2) {
return abs(a[i] - a[i + 1]);
} else if (dp[i] > -1)
return dp[i];
else {
s = min(abs(a[i] - a[i + 1]) + go(i + 1), abs(a[i + 2] - a[i]) + go(i + 2));
dp[i] = s;
}
return s;
}
void solve() {
ll t;
t = 1;
while (t--) {
// ll n;
cin >> n;
// ll a[n];
FOR(i, 0, n)
cin >> a[i];
memset(dp, -1, sizeof(dp));
cout << go(0);
}
}
int main() {
std::ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int start = clock();
#ifdef ONLINE_JUDGE
#else
freopen("input.in", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
solve();
int stop = clock();
#ifdef ONLINE_JUDGE
#else
// cout << setprecision(6) << fixed << (stop - start) * 1000.00 /
// double(CLOCKS_PER_SEC)<< endl;
#endif
}
|
// *
// *
// * Created By :hozaifa wahid
// * "mai maut ko takia aur kafan ko chadar banakar sota hu"
// *------------------------------------
// * OS : Ubuntu 16.04
// * Language : CPP14
// * Editor : Sublime Text 3
// * C++ compiler : g++
// *
// *
// https://www.geeksforgeeks.org/find-the-point-where-maximum-intervals-overlap/
#include <bits/stdc++.h>
#define pb push_back
// #define mp make_pair
#define inf 1000000007
#define fr first
#define sc second
#define eps 1e-9
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define sni(x) scanf("%d", &x)
#define snl(x) scanf("%lld", &x)
#define snc(x) scanf("%c", &c);
#define rep(n) for (int i = 0; i < n; i++)
#define repc(i, n) for (int i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
ll MOD = 1000000007;
vector<ll> v[100055];
void sieve() {
for (int n = 1; n <= 100055; n++) {
for (int i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
// If divisors are equal, print only one
if (n / i == i)
v[n].push_back(i);
else // Otherwise print both
{
v[n].push_back(i);
v[n].push_back(n / i);
}
}
}
}
}
ll pw(ll a, ll b) {
if (b == 0)
return 1;
ll x = pw(a, b / 2);
x = (x * x) % MOD;
if (b % 2)
x = (x * a) % MOD;
return x;
}
ll n, s;
ll a[100005];
int ok = 0;
// ll res=0;
ll dp[100005];
ll go(ll i) {
if (i == n - 1) {
return 0;
} else if (i == n - 2) {
return abs(a[i] - a[i + 1]);
} else if (dp[i] > -1)
return dp[i];
else {
s = min(abs(a[i] - a[i + 1]) + go(i + 1), abs(a[i + 2] - a[i]) + go(i + 2));
dp[i] = s;
}
return s;
}
void solve() {
ll t;
t = 1;
while (t--) {
// ll n;
cin >> n;
// ll a[n];
FOR(i, 0, n)
cin >> a[i];
memset(dp, -1, sizeof(dp));
cout << go(0);
}
}
int main() {
std::ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int start = clock();
#ifdef ONLINE_JUDGE
#else
// freopen("input.in" , "r" , stdin);
// freopen("output.txt", "w", stdout);
#endif
solve();
int stop = clock();
#ifdef ONLINE_JUDGE
#else
// cout << setprecision(6) << fixed << (stop - start) * 1000.00 /
// double(CLOCKS_PER_SEC)<< endl;
#endif
}
|
replace
| 107 | 109 | 107 | 109 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define all(V) V.begin(), V.end()
#define see(x) cerr << #x << " = " << x << "\n";
#define Unique(V) sort(all(V)), V.erase(unique(all(V)), V.end())
typedef long long int LL;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 2e3 + 5;
int n, a[N];
int dp[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
dp[i] = inf;
dp[n] = 0;
for (int i = n; i >= 1; i--) {
for (int j = 1; j <= 2; j++) {
if (i + j <= n) {
dp[i] = min(dp[i], dp[i + j] + abs(a[i + j] - a[i]));
}
}
}
cout << dp[1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define all(V) V.begin(), V.end()
#define see(x) cerr << #x << " = " << x << "\n";
#define Unique(V) sort(all(V)), V.erase(unique(all(V)), V.end())
typedef long long int LL;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;
int n, a[N];
int dp[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
dp[i] = inf;
dp[n] = 0;
for (int i = n; i >= 1; i--) {
for (int j = 1; j <= 2; j++) {
if (i + j <= n) {
dp[i] = min(dp[i], dp[i + j] + abs(a[i + j] - a[i]));
}
}
}
cout << dp[1] << endl;
return 0;
}
|
replace
| 13 | 14 | 13 | 14 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int h[N];
int dp[N];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> h[i];
dp[n - 1] = 0;
dp[n - 2] = abs(h[n - 1] - h[n - 2]);
for (int i = n - 3; i >= 0; i++)
dp[i] =
min(dp[i + 1] + abs(h[i] - h[i + 1]), dp[i + 2] + abs(h[i] - h[i + 2]));
cout << dp[0];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int h[N];
int dp[N];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> h[i];
dp[n - 1] = 0;
dp[n - 2] = abs(h[n - 1] - h[n - 2]);
for (int i = n - 3; i >= 0; i--)
dp[i] =
min(dp[i + 1] + abs(h[i] - h[i + 1]), dp[i + 2] + abs(h[i] - h[i + 2]));
cout << dp[0];
return 0;
}
|
replace
| 13 | 14 | 13 | 14 |
-11
| |
p03160
|
C++
|
Runtime Error
|
#include "bits/stdc++.h"
using namespace std;
int n, h[5000], dp[5000];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> 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++) {
dp[i] =
min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
}
cout << dp[n - 1];
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
int n, h[10000000], dp[10000000];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> 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++) {
dp[i] =
min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
}
cout << dp[n - 1];
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
template <typename T> T load() {
T r;
cin >> r;
return r;
}
template <typename T> vector<T> loadMany(int n) {
vector<T> rs(n);
generate(rs.begin(), rs.end(), &load<T>);
return rs;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
while (true)
new int[10000];
auto n = load<int>();
auto height = loadMany<int>(n);
auto dyn = vector<int>(n);
dyn[0] = 0;
for (auto i = 1; i < n; ++i) {
dyn[i] = dyn[i - 1] + abs(height[i - 1] - height[i]);
if (i >= 2)
dyn[i] = min(dyn[i], dyn[i - 2] + abs(height[i] - height[i - 2]));
}
cout << dyn[n - 1] << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T> T load() {
T r;
cin >> r;
return r;
}
template <typename T> vector<T> loadMany(int n) {
vector<T> rs(n);
generate(rs.begin(), rs.end(), &load<T>);
return rs;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
auto n = load<int>();
auto height = loadMany<int>(n);
auto dyn = vector<int>(n);
dyn[0] = 0;
for (auto i = 1; i < n; ++i) {
dyn[i] = dyn[i - 1] + abs(height[i - 1] - height[i]);
if (i >= 2)
dyn[i] = min(dyn[i], dyn[i - 2] + abs(height[i] - height[i - 2]));
}
cout << dyn[n - 1] << '\n';
}
|
delete
| 17 | 19 | 17 | 17 |
-6
|
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define endl "\n"
#define mod 1000000007
#define INF 1e18
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define w(x) \
int x; \
cin >> x; \
while (x--)
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void rwf() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "rt", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int xpowery(int x, int y) {
int ans = 1;
while (y) {
if (y & 1)
ans = (ans * x) % mod;
x = (x * x) % mod;
y = y / 2;
}
return ans;
}
const int N = 1e5 + 5;
int h[N], n;
int cache[N];
int solve(int m) {
if (m > n)
return cache[m] = 1e9;
if (m == n)
return cache[m] = 0;
if (cache[m] != -1)
return cache[m];
return cache[m] = min(abs(h[m] - h[m + 1]) + solve(m + 1),
abs(h[m] - h[m + 2]) + solve(m + 2));
}
int32_t main() {
IOS;
rwf();
cin >> n;
memset(cache, -1, sizeof(cache));
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
int ans = solve(1);
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define endl "\n"
#define mod 1000000007
#define INF 1e18
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define w(x) \
int x; \
cin >> x; \
while (x--)
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void rwf() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "rt", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int xpowery(int x, int y) {
int ans = 1;
while (y) {
if (y & 1)
ans = (ans * x) % mod;
x = (x * x) % mod;
y = y / 2;
}
return ans;
}
const int N = 1e5 + 5;
int h[N], n;
int cache[N];
int solve(int m) {
if (m > n)
return cache[m] = 1e9;
if (m == n)
return cache[m] = 0;
if (cache[m] != -1)
return cache[m];
return cache[m] = min(abs(h[m] - h[m + 1]) + solve(m + 1),
abs(h[m] - h[m + 2]) + solve(m + 2));
}
int32_t main() {
IOS;
// rwf();
cin >> n;
memset(cache, -1, sizeof(cache));
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
int ans = solve(1);
cout << ans;
return 0;
}
|
replace
| 67 | 68 | 67 | 68 |
0
| |
p03160
|
C++
|
Runtime Error
|
// 98tarunkumar
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define lop(i, n) for (int i = 0; i < n; i++)
#define rlop(i, n) for (int i = n; i > 0; i--)
#define lli long long int
#define MOD 1000000007
#define f(i, a, b) for (i = a; i < b; i++)
#define ainp(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define aout(a, n) \
for (int i = 0; i < n; i++) \
cout << a[i] << " ";
#define ss \
ios::sync_with_stdio(false); \
cin.tie(NULL);
#define vi vector<int>
#define ln cout << "\n"
int main() {
ss;
#ifndef ONLINE_JUDGE
freopen("cf_inp.txt", "r", stdin);
freopen("cf_oup.txt", "w", stdout);
#endif
int n;
cin >> n;
int a[n];
ainp(a, n) if (n == 1) {
cout << 0;
ln;
}
else if (n == 2) {
cout << a[1] - a[0];
ln;
}
else {
int dp[n];
dp[0] = 0;
dp[1] = abs(a[1] - a[0]);
for (int i = 2; i < n; i++) {
dp[i] = min(abs(a[i] - a[i - 2]) + dp[i - 2],
dp[i - 1] + abs(a[i] - a[i - 1]));
}
// aout(dp,n)ln;
cout << dp[n - 1];
}
}
|
// 98tarunkumar
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define lop(i, n) for (int i = 0; i < n; i++)
#define rlop(i, n) for (int i = n; i > 0; i--)
#define lli long long int
#define MOD 1000000007
#define f(i, a, b) for (i = a; i < b; i++)
#define ainp(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define aout(a, n) \
for (int i = 0; i < n; i++) \
cout << a[i] << " ";
#define ss \
ios::sync_with_stdio(false); \
cin.tie(NULL);
#define vi vector<int>
#define ln cout << "\n"
int main() {
ss;
/*#ifndef ONLINE_JUDGE
freopen("cf_inp.txt","r",stdin);
freopen("cf_oup.txt","w",stdout);
#endif*/
int n;
cin >> n;
int a[n];
ainp(a, n) if (n == 1) {
cout << 0;
ln;
}
else if (n == 2) {
cout << a[1] - a[0];
ln;
}
else {
int dp[n];
dp[0] = 0;
dp[1] = abs(a[1] - a[0]);
for (int i = 2; i < n; i++) {
dp[i] = min(abs(a[i] - a[i - 2]) + dp[i - 2],
dp[i - 1] + abs(a[i] - a[i - 1]));
}
// aout(dp,n)ln;
cout << dp[n - 1];
}
}
|
replace
| 26 | 30 | 26 | 30 |
0
| |
p03160
|
C++
|
Time Limit Exceeded
|
// i_am_arin
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<long long> vll;
typedef vector<string> vs;
#define f(i, a, n) for (ll i = a; i < (ll)n; i++)
#define f2(i, a, b) for (ll i = a; i <= (ll)b; i++)
#define PB push_back
#define FF first
#define SS second
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
ll dp[100005];
ll a[100005];
ll n;
void fill() { f(i, 0, 100005) dp[i] = -1; }
ll go(ll n) {
if (n == 2)
return abs(a[n] - a[n - 1]);
if (n == 1)
return 0;
if (n < 0)
return INF;
// if(dp[n]!=-1) return dp[n];
return dp[n] = min((go(n - 1) + abs(a[n] - a[n - 1])),
go(n - 2) + abs(a[n] - a[n - 2]));
}
void solve() {
cin >> n;
fill();
f(i, 1, n + 1) cin >> a[i];
cout << go(n) << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
|
// i_am_arin
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<long long> vll;
typedef vector<string> vs;
#define f(i, a, n) for (ll i = a; i < (ll)n; i++)
#define f2(i, a, b) for (ll i = a; i <= (ll)b; i++)
#define PB push_back
#define FF first
#define SS second
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
ll dp[100005];
ll a[100005];
ll n;
void fill() { f(i, 0, 100005) dp[i] = -1; }
ll go(ll n) {
if (n == 2)
return abs(a[n] - a[n - 1]);
if (n == 1)
return 0;
if (n < 0)
return INF;
if (dp[n] != -1)
return dp[n];
return dp[n] = min((go(n - 1) + abs(a[n] - a[n - 1])),
go(n - 2) + abs(a[n] - a[n - 2]));
}
void solve() {
cin >> n;
fill();
f(i, 1, n + 1) cin >> a[i];
cout << go(n) << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
|
replace
| 31 | 32 | 31 | 33 |
TLE
| |
p03160
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
using namespace std;
const int MAX_T = 10100;
const long long INF = 1LL << 60;
template <class T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <class T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
int main() {
int N;
cin >> N;
long long h[MAX_T];
long long dp[MAX_T];
for (int i = 0; i < N; i++)
scanf("%lld", &h[i]);
for (int i = 0; i < N; i++) {
dp[i] = INF;
}
dp[0] = 0;
for (int i = 0; i < N; i++) {
chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
}
cout << dp[N - 1] << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
const int MAX_T = 100100;
const long long INF = 1LL << 60;
template <class T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <class T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
int main() {
int N;
cin >> N;
long long h[MAX_T];
long long dp[MAX_T];
for (int i = 0; i < N; i++)
scanf("%lld", &h[i]);
for (int i = 0; i < N; i++) {
dp[i] = INF;
}
dp[0] = 0;
for (int i = 0; i < N; i++) {
chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
}
cout << dp[N - 1] << endl;
return 0;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p03160
|
C++
|
Time Limit Exceeded
|
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif
#define y0 qvya13579
#define y1 qvyb24680
#define j0 qvja13579
#define j1 qvjb24680
#define next qvne13579xt
#define prev qvpr13579ev
#define INF 1000000007
#define MOD 1000000007
#define PI acos(-1.0)
#define endl "\n"
#define IOS \
cin.tie(0); \
ios::sync_with_stdio(false)
#define M_P make_pair
#define PU_B push_back
#define PU_F push_front
#define PO_B pop_back
#define PO_F pop_front
#define U_B upper_bound
#define L_B lower_bound
#define B_S binary_search
#define PR_Q priority_queue
#define FIR first
#define SEC second
#if __cplusplus < 201103L
#define stoi(argument_string) atoi((argument_string).c_str())
#endif
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP_R(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define FOR(i, m, n) for (int i = ((int)(m)); i < (int)(n); ++i)
#define FOR_R(i, m, n) for (int i = ((int)(m)-1); i >= (int)(n); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SIZ(x) ((int)(x).size())
#define COUT(x) cout << (x) << endl
#define CIN(x) cin >> (x)
#define CIN2(x, y) cin >> (x) >> (y)
#define CIN3(x, y, z) cin >> (x) >> (y) >> (z)
#define CIN4(x, y, z, w) cin >> (x) >> (y) >> (z) >> (w)
#define SCAND(x) scanf("%d", &(x))
#define SCAND2(x, y) scanf("%d%d", &(x), &(y))
#define SCAND3(x, y, z) scanf("%d%d%d", &(x), &(y), &(z))
#define SCAND4(x, y, z, w) scanf("%d%d%d%d", &(x), &(y), &(z), &(w))
#define SCANLLD(x) scanf("%lld", &(x))
#define SCANLLD2(x, y) scanf("%lld%lld", &(x), &(y))
#define SCANLLD3(x, y, z) scanf("%lld%lld%lld", &(x), &(y), &(z))
#define SCANLLD4(x, y, z, w) scanf("%lld%lld%lld%lld", &(x), &(y), &(z), &(w))
#define PRINTD(x) printf("%d\n", (x))
#define PRINTLLD(x) printf("%lld\n", (x))
typedef long long int lli;
using namespace std;
bool compare_by_2nd(pair<int, int> a, pair<int, int> b) {
if (a.second != b.second) {
return a.second < b.second;
} else {
return a.first < b.first;
}
}
int ctoi(char c) {
if (c >= '0' and c <= '9') {
return (int)(c - '0');
}
return -1;
}
int alphabet_pos(char c) {
if (c >= 'a' and c <= 'z') {
return (int)(c - 'a');
}
return -1;
}
int alphabet_pos_capital(char c) {
if (c >= 'A' and c <= 'Z') {
return (int)(c - 'A');
}
return -1;
}
vector<string> split(string str, char ch) {
int first = 0;
int last = str.find_first_of(ch);
if (last == string::npos) {
last = SIZ(str);
}
vector<string> result;
while (first < SIZ(str)) {
string Ssubstr(str, first, last - first);
result.push_back(Ssubstr);
first = last + 1;
last = str.find_first_of(ch, first);
if (last == string::npos) {
last = SIZ(str);
}
}
return result;
}
int gcd(int a, int b) // assuming a,b >= 1
{
if (a < b) {
return gcd(b, a);
}
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
int lcm(int a, int b) // assuming a,b >= 1
{
return a * b / gcd(a, b);
}
/*------------------ the end of the template -----------------------*/
int dp(int i, vector<int> &h, vector<int> &cst) {
if (cst[i] > 0) {
return cst[i];
}
if (i == 0) {
return cst[0] = 0;
}
if (i == 1) {
return cst[1] = abs(h[0] - h[1]);
}
return cst[i] = min(dp(i - 1, h, cst) + abs(h[i] - h[i - 1]),
dp(i - 2, h, cst) + abs(h[i] - h[i - 2]));
}
int main() {
// IOS; /* making cin faster */
int N;
SCAND(N);
vector<int> h(N);
REP(i, N) { SCAND(h[i]); }
vector<int> cst(N, -1);
PRINTD(dp(N - 1, h, cst));
}
|
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif
#define y0 qvya13579
#define y1 qvyb24680
#define j0 qvja13579
#define j1 qvjb24680
#define next qvne13579xt
#define prev qvpr13579ev
#define INF 1000000007
#define MOD 1000000007
#define PI acos(-1.0)
#define endl "\n"
#define IOS \
cin.tie(0); \
ios::sync_with_stdio(false)
#define M_P make_pair
#define PU_B push_back
#define PU_F push_front
#define PO_B pop_back
#define PO_F pop_front
#define U_B upper_bound
#define L_B lower_bound
#define B_S binary_search
#define PR_Q priority_queue
#define FIR first
#define SEC second
#if __cplusplus < 201103L
#define stoi(argument_string) atoi((argument_string).c_str())
#endif
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP_R(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define FOR(i, m, n) for (int i = ((int)(m)); i < (int)(n); ++i)
#define FOR_R(i, m, n) for (int i = ((int)(m)-1); i >= (int)(n); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SIZ(x) ((int)(x).size())
#define COUT(x) cout << (x) << endl
#define CIN(x) cin >> (x)
#define CIN2(x, y) cin >> (x) >> (y)
#define CIN3(x, y, z) cin >> (x) >> (y) >> (z)
#define CIN4(x, y, z, w) cin >> (x) >> (y) >> (z) >> (w)
#define SCAND(x) scanf("%d", &(x))
#define SCAND2(x, y) scanf("%d%d", &(x), &(y))
#define SCAND3(x, y, z) scanf("%d%d%d", &(x), &(y), &(z))
#define SCAND4(x, y, z, w) scanf("%d%d%d%d", &(x), &(y), &(z), &(w))
#define SCANLLD(x) scanf("%lld", &(x))
#define SCANLLD2(x, y) scanf("%lld%lld", &(x), &(y))
#define SCANLLD3(x, y, z) scanf("%lld%lld%lld", &(x), &(y), &(z))
#define SCANLLD4(x, y, z, w) scanf("%lld%lld%lld%lld", &(x), &(y), &(z), &(w))
#define PRINTD(x) printf("%d\n", (x))
#define PRINTLLD(x) printf("%lld\n", (x))
typedef long long int lli;
using namespace std;
bool compare_by_2nd(pair<int, int> a, pair<int, int> b) {
if (a.second != b.second) {
return a.second < b.second;
} else {
return a.first < b.first;
}
}
int ctoi(char c) {
if (c >= '0' and c <= '9') {
return (int)(c - '0');
}
return -1;
}
int alphabet_pos(char c) {
if (c >= 'a' and c <= 'z') {
return (int)(c - 'a');
}
return -1;
}
int alphabet_pos_capital(char c) {
if (c >= 'A' and c <= 'Z') {
return (int)(c - 'A');
}
return -1;
}
vector<string> split(string str, char ch) {
int first = 0;
int last = str.find_first_of(ch);
if (last == string::npos) {
last = SIZ(str);
}
vector<string> result;
while (first < SIZ(str)) {
string Ssubstr(str, first, last - first);
result.push_back(Ssubstr);
first = last + 1;
last = str.find_first_of(ch, first);
if (last == string::npos) {
last = SIZ(str);
}
}
return result;
}
int gcd(int a, int b) // assuming a,b >= 1
{
if (a < b) {
return gcd(b, a);
}
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
int lcm(int a, int b) // assuming a,b >= 1
{
return a * b / gcd(a, b);
}
/*------------------ the end of the template -----------------------*/
int dp(int i, vector<int> &h, vector<int> &cst) {
if (cst[i] >= 0) {
return cst[i];
}
if (i == 0) {
return cst[0] = 0;
}
if (i == 1) {
return cst[1] = abs(h[0] - h[1]);
}
return cst[i] = min(dp(i - 1, h, cst) + abs(h[i] - h[i - 1]),
dp(i - 2, h, cst) + abs(h[i] - h[i - 2]));
}
int main() {
// IOS; /* making cin faster */
int N;
SCAND(N);
vector<int> h(N);
REP(i, N) { SCAND(h[i]); }
vector<int> cst(N, -1);
PRINTD(dp(N - 1, h, cst));
}
|
replace
| 212 | 213 | 212 | 213 |
TLE
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define tam 10001
int dp[tam], A[tam], n;
int solver(int index) {
if (dp[index] != -1)
return dp[index];
if (index <= 1)
return dp[index] = abs(A[0] - A[index]);
return dp[index] = min(solver(index - 1) + abs(A[index] - A[index - 1]),
solver(index - 2) + abs(A[index] - A[index - 2]));
}
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> A[i];
memset(dp, -1, sizeof dp);
dp[0] = 0;
cout << solver(n - 1) << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define tam 100001
int dp[tam], A[tam], n, pr = 0;
int solver(int index) {
if (dp[index] != -1)
return dp[index];
if (index <= 1)
return dp[index] = abs(A[0] - A[index]);
return dp[index] = min(solver(index - 1) + abs(A[index] - A[index - 1]),
solver(index - 2) + abs(A[index] - A[index - 2]));
}
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> A[i];
memset(dp, -1, sizeof dp);
dp[0] = 0;
cout << solver(n - 1) << "\n";
return 0;
}
|
replace
| 3 | 5 | 3 | 5 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, i;
cin >> N;
int *h = new int(N);
int *d = new int(N);
for (i = 0; i < N; i++)
cin >> h[i];
d[0] = 0;
d[1] = abs(h[1] - h[0]);
for (i = 2; i < N; i++)
d[i] =
min(d[i - 1] + abs(h[i] - h[i - 1]), d[i - 2] + abs(h[i] - h[i - 2]));
cout << d[N - 1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, i;
cin >> N;
int h[100000];
int d[100000];
for (i = 0; i < N; i++)
cin >> h[i];
d[0] = 0;
d[1] = abs(h[1] - h[0]);
for (i = 2; i < N; i++)
d[i] =
min(d[i - 1] + abs(h[i] - h[i - 1]), d[i - 2] + abs(h[i] - h[i - 2]));
cout << d[N - 1] << endl;
return 0;
}
|
replace
| 6 | 8 | 6 | 8 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS \
; \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define MX 80
#define FF \
freopen("input.in", "r", stdin); \
freopen("output.txt", "w", stdout);
int n;
int a[MX];
int dp[MX];
int f(int i) {
if (i == n)
return 0;
if (dp[i] != -1)
return dp[i];
if (i < n - 1)
return dp[i] = min(f(i + 1) + abs(a[i] - a[i + 1]),
f(i + 2) + abs(a[i] - a[i + 2]));
else
return dp[i] = f(i + 1) + abs(a[i] - a[i + 1]);
}
int main() {
// FF;
IOS;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
memset(dp, -1, sizeof dp);
cout << f(1);
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS \
; \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define MX 100001
#define FF \
freopen("input.in", "r", stdin); \
freopen("output.txt", "w", stdout);
int n;
int a[MX];
int dp[MX];
int f(int i) {
if (i == n)
return 0;
if (dp[i] != -1)
return dp[i];
if (i < n - 1)
return dp[i] = min(f(i + 1) + abs(a[i] - a[i + 1]),
f(i + 2) + abs(a[i] - a[i + 2]));
else
return dp[i] = f(i + 1) + abs(a[i] - a[i + 1]);
}
int main() {
// FF;
IOS;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
memset(dp, -1, sizeof dp);
cout << f(1);
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define fast \
ios::sync_with_stdio(NULL); \
cin.tie(0); \
cout.tie(0);
#define make_pair mp
#define pb push_back
#define ALL(s) s.begin(), s.end()
using namespace std;
typedef long long ll;
const int maxn = 1 << 21;
const int mod = 1e9 + 7;
const int INF = 1e9 + 5;
int h[100005];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> h[i];
vector<int> dp(n, INF);
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j <= i + 2; i++) {
if (j < n)
dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
}
}
cout << dp[n - 1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define fast \
ios::sync_with_stdio(NULL); \
cin.tie(0); \
cout.tie(0);
#define make_pair mp
#define pb push_back
#define ALL(s) s.begin(), s.end()
using namespace std;
typedef long long ll;
const int maxn = 1 << 21;
const int mod = 1e9 + 7;
const int INF = 1e9 + 5;
int h[100005];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> h[i];
vector<int> dp(n, INF);
dp[0] = 0;
for (int i = 0; i < n; i++) {
if (i + 1 < n)
dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
if (i + 2 < n)
dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
}
cout << dp[n - 1] << endl;
return 0;
}
|
replace
| 22 | 26 | 22 | 26 |
-11
| |
p03160
|
C++
|
Runtime Error
|
// https://cs.stackexchange.com/questions/84426/find-a-node-with-maximum-distance-from-given-node-in-a-tree
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including
// tree_order_statistics_node_update using namespace __gnu_pbds; #include
// <ext/rope> //header with rope using namespace __gnu_cxx; #define ordered_set
// tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order tells index pr kon hai..
// order_by_key tells ki us element se kitne strictly smaller element hai...
#define mod 1000000007
#define INF 1000000000000000000
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Senky_Bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
ll fact[1000007];
ll mdpower(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1)
res = (res % mod * a % mod) % mod;
b /= 2;
a = (a % mod * a % mod) % mod;
}
return res;
}
void factorial() {
fact[0] = 1;
for (int i = 1; i < 1000007; i++)
fact[i] = (fact[i - 1] % mod * i % mod) % mod;
}
ll inverse(ll a, ll b) { return mdpower(a, b - 2); }
ll power(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1)
res = (res * a);
a = (a * a);
b /= 2;
}
return res;
}
int main() {
Senky_Bansal IIIT_ALLAHABAD
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll n;
cin >> n;
ll h[n];
for (int i = 0; i < n; i++) {
cin >> h[i];
}
ll dp[n + 1];
for (int i = 1; i <= n; i++) {
dp[i] = INF;
}
dp[0] = 0;
for (int i = 0; i < n; i++) {
if (i + 1 < n)
dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
if (i + 2 < n)
dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
}
cout << dp[n - 1] << endl;
}
|
// https://cs.stackexchange.com/questions/84426/find-a-node-with-maximum-distance-from-given-node-in-a-tree
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including
// tree_order_statistics_node_update using namespace __gnu_pbds; #include
// <ext/rope> //header with rope using namespace __gnu_cxx; #define ordered_set
// tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order tells index pr kon hai..
// order_by_key tells ki us element se kitne strictly smaller element hai...
#define mod 1000000007
#define INF 1000000000000000000
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Senky_Bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
ll fact[1000007];
ll mdpower(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1)
res = (res % mod * a % mod) % mod;
b /= 2;
a = (a % mod * a % mod) % mod;
}
return res;
}
void factorial() {
fact[0] = 1;
for (int i = 1; i < 1000007; i++)
fact[i] = (fact[i - 1] % mod * i % mod) % mod;
}
ll inverse(ll a, ll b) { return mdpower(a, b - 2); }
ll power(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1)
res = (res * a);
a = (a * a);
b /= 2;
}
return res;
}
int main() {
Senky_Bansal IIIT_ALLAHABAD
ll n;
cin >> n;
ll h[n];
for (int i = 0; i < n; i++) {
cin >> h[i];
}
ll dp[n + 1];
for (int i = 1; i <= n; i++) {
dp[i] = INF;
}
dp[0] = 0;
for (int i = 0; i < n; i++) {
if (i + 1 < n)
dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
if (i + 2 < n)
dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
}
cout << dp[n - 1] << endl;
}
|
replace
| 54 | 59 | 54 | 55 |
-11
| |
p03160
|
C++
|
Runtime Error
|
/******************************************
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define fin for (int i = 1; i <= n; i++)
#define fiab for (int i = a; i < b; i++)
#define fi1b for (int i = 1; i <= b; i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
int m;
int h[100004];
int n;
LL dp[100004];
long frog1(int i) {
if (i == 1) {
return 0;
}
if (i == 2) {
return (abs(h[i] - h[i - 1]));
}
LL &ans = dp[i];
if (ans != -1) {
return ans;
}
ans = min(frog1(i - 1) + abs(h[i] - h[i - 1]),
frog1(i - 2) + abs(h[i] - h[i - 2]));
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ios_base &scientific(ios_base & str);
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
// this can be opted out if you want to print the output to the sublime
// console
freopen("output.txt", "w", stdout);
#endif
memset(dp, -1, sizeof(dp));
cin >> n;
m = n;
fin { cin >> h[i]; }
long p = frog1(n);
cout << p << endl;
return 0;
}
|
/******************************************
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define fin for (int i = 1; i <= n; i++)
#define fiab for (int i = a; i < b; i++)
#define fi1b for (int i = 1; i <= b; i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
int m;
int h[100004];
int n;
LL dp[100004];
long frog1(int i) {
if (i == 1) {
return 0;
}
if (i == 2) {
return (abs(h[i] - h[i - 1]));
}
LL &ans = dp[i];
if (ans != -1) {
return ans;
}
ans = min(frog1(i - 1) + abs(h[i] - h[i - 1]),
frog1(i - 2) + abs(h[i] - h[i - 2]));
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ios_base &scientific(ios_base & str);
memset(dp, -1, sizeof(dp));
cin >> n;
m = n;
fin { cin >> h[i]; }
long p = frog1(n);
cout << p << endl;
return 0;
}
|
delete
| 43 | 52 | 43 | 43 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) \
int n; \
cin >> n; \
int a[n]; \
rep(i, n) cin >> a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin.sync_with_stdio(0);
cin.tie(0);
cin.exceptions(cin.failbit);
int n;
cin >> n;
int dp[n];
int h[n];
rep(i, n) cin >> h[i];
dp[0] = 0;
dp[1] = abs(h[1] - h[0]);
for (int i = 2; i < n; i++) {
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
}
cout << dp[n - 1];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) \
int n; \
cin >> n; \
int a[n]; \
rep(i, n) cin >> a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
cin.sync_with_stdio(0);
cin.tie(0);
cin.exceptions(cin.failbit);
int n;
cin >> n;
int dp[n];
int h[n];
rep(i, n) cin >> h[i];
dp[0] = 0;
dp[1] = abs(h[1] - h[0]);
for (int i = 2; i < n; i++) {
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
}
cout << dp[n - 1];
return 0;
}
|
replace
| 24 | 28 | 24 | 28 |
-6
|
terminate called after throwing an instance of 'std::__ios_failure'
what(): basic_ios::clear: iostream error
|
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(nullptr); \
cout.tie(nullptr);
#define mp make_pair
#define pb push_back
const int mod = 1e9 + 7;
bool isPrime(int n) {
for (int i = 2; i < n; i++)
if (n % i == 0)
return false;
return true;
}
struct cmp {
bool operator()(const pair<int, int> &a, const pair<int, int> &b) {
int len1 = a.second - a.first + 1;
int len2 = b.second - b.first + 1;
if (len1 != len2)
return len1 > len2;
return a.first < b.first;
}
};
bool comp(pair<pair<int, int>, int> &a, pair<pair<int, int>, int> &b) {
int diff1 = abs(a.first.first - a.first.second);
int diff2 = abs(b.first.first - b.first.second);
if (diff1 > diff2)
return true;
return false;
// return (a.first.second > b.first.second);
}
void findAns() {
int n;
cin >> n;
int height[n];
for (auto &it : height)
cin >> it;
int dp[n];
dp[0] = 0;
dp[1] = abs(height[0] - height[1]);
for (int i = 2; i < n; i++) {
dp[i] = min(dp[i - 1] + abs(height[i - 1] - height[i]),
dp[i - 2] + abs(height[i - 2] - height[i]));
}
cout << dp[n - 1];
return;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fastio;
// ll int t;
// cin >> t;
// while (t--)
findAns();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(nullptr); \
cout.tie(nullptr);
#define mp make_pair
#define pb push_back
const int mod = 1e9 + 7;
bool isPrime(int n) {
for (int i = 2; i < n; i++)
if (n % i == 0)
return false;
return true;
}
struct cmp {
bool operator()(const pair<int, int> &a, const pair<int, int> &b) {
int len1 = a.second - a.first + 1;
int len2 = b.second - b.first + 1;
if (len1 != len2)
return len1 > len2;
return a.first < b.first;
}
};
bool comp(pair<pair<int, int>, int> &a, pair<pair<int, int>, int> &b) {
int diff1 = abs(a.first.first - a.first.second);
int diff2 = abs(b.first.first - b.first.second);
if (diff1 > diff2)
return true;
return false;
// return (a.first.second > b.first.second);
}
void findAns() {
int n;
cin >> n;
int height[n];
for (auto &it : height)
cin >> it;
int dp[n];
dp[0] = 0;
dp[1] = abs(height[0] - height[1]);
for (int i = 2; i < n; i++) {
dp[i] = min(dp[i - 1] + abs(height[i - 1] - height[i]),
dp[i - 2] + abs(height[i - 2] - height[i]));
}
cout << dp[n - 1];
return;
}
int main() {
fastio;
// ll int t;
// cin >> t;
// while (t--)
findAns();
return 0;
}
|
replace
| 55 | 59 | 55 | 56 |
-11
| |
p03160
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <iostream>
#define mp make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
const int MAXN = 1e5 + 7;
template <typename T> inline T read() {
T res = 0, flag = 1;
char in = getchar();
while (!isdigit(in)) {
if (in == '-')
flag = -1;
in = getchar();
}
while (isdigit(in)) {
res = (res << 1) + (res << 3) + in - '0';
in = getchar();
}
return res * flag;
}
template <typename T> inline void chkmax(T &a, T b) {
if (a < b)
a = b;
}
template <typename T> inline void chkmin(T &a, T b) {
if (a > b)
a = b;
}
int dp[MAXN], h[MAXN], n;
inline void solve() {
n = read<int>();
for (int i = 1; i <= n; ++i)
h[i] = read<int>();
memset(dp, 0x3f, sizeof dp);
dp[0] = dp[1] = 0;
for (int i = 2; i <= n; ++i) {
chkmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
if (i - 2)
chkmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
}
printf("%d\n", dp[n]);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("A.in", "r", stdin);
freopen("A.out", "w", stdout);
#endif
solve();
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <iostream>
#define mp make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
const int MAXN = 1e5 + 7;
template <typename T> inline T read() {
T res = 0, flag = 1;
char in = getchar();
while (!isdigit(in)) {
if (in == '-')
flag = -1;
in = getchar();
}
while (isdigit(in)) {
res = (res << 1) + (res << 3) + in - '0';
in = getchar();
}
return res * flag;
}
template <typename T> inline void chkmax(T &a, T b) {
if (a < b)
a = b;
}
template <typename T> inline void chkmin(T &a, T b) {
if (a > b)
a = b;
}
int dp[MAXN], h[MAXN], n;
inline void solve() {
n = read<int>();
for (int i = 1; i <= n; ++i)
h[i] = read<int>();
memset(dp, 0x3f, sizeof dp);
dp[0] = dp[1] = 0;
for (int i = 2; i <= n; ++i) {
chkmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
if (i - 2)
chkmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
}
printf("%d\n", dp[n]);
}
int main() {
solve();
return 0;
}
|
delete
| 56 | 60 | 56 | 56 |
TLE
| |
p03160
|
C++
|
Runtime Error
|
#include <iostream>
#include <vector>
using namespace std;
const int INF = 1e9 + 5;
int main() {
int n;
int h[10010];
cin >> n;
for (int i = 0; i < n; i++)
cin >> h[i];
vector<int> dp(n, INF);
dp[0] = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j <= i + 2; j++) {
if (j < n) {
dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
}
}
}
cout << dp[n - 1] << "\n";
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
const int INF = 1e9 + 5;
int main() {
int n;
int h[100010];
cin >> n;
for (int i = 0; i < n; i++)
cin >> h[i];
vector<int> dp(n, INF);
dp[0] = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j <= i + 2; j++) {
if (j < n) {
dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
}
}
}
cout << dp[n - 1] << "\n";
return 0;
}
|
replace
| 9 | 10 | 9 | 10 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int dp[10005];
int h[10005];
cin >> 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++) {
dp[i] =
min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
}
cout << dp[n - 1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int dp[100005];
int h[100005];
cin >> 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++) {
dp[i] =
min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
}
cout << dp[n - 1] << endl;
return 0;
}
|
replace
| 4 | 6 | 4 | 6 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
int a[n];
int dp[n];
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++)
dp[i] =
min(dp[i - 2] + abs(a[i - 2] - a[i]), dp[i - 1] + abs(a[i - 1] - a[i]));
cout << dp[n - 1];
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
int a[n];
int dp[n];
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++)
dp[i] =
min(dp[i - 2] + abs(a[i - 2] - a[i]), dp[i - 1] + abs(a[i - 1] - a[i]));
cout << dp[n - 1];
}
|
replace
| 5 | 7 | 5 | 7 |
0
| |
p03160
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define INF (int)(1e9)
// The recurrence we will be optimizing is
// c(n) = min(c(n - 1) + cost(n, n - 1),
// c(n - 2) + cost(n, n - 2))
// h[i] is the "value" of stone i
// cost(i, j) = abs(h[i] - h[j])
// I think this way is more natural
int solve_backwards(const vector<int> &h, int N) {
if (N < 0)
return INF;
if (N == 0)
return 0;
return min(solve_backwards(h, N - 1) + abs(h[N] - h[N - 1]),
solve_backwards(h, N - 2) + abs(h[N] - h[N - 2]));
}
int solve_forwards(const vector<int> &h, int N) {
if ((size_t)N >= h.size())
return INF;
if ((size_t)N == h.size() - 1)
return 0;
return min(solve_forwards(h, N + 1) + abs(h[N] - h[N + 1]),
solve_forwards(h, N + 2) + abs(h[N] - h[N + 2]));
}
// position -> cost
// the shortest path to i will inform us about the shortest
// path to get to i + 1 and i + 2
// this will solve to the shortest path to N in general
// This is really just adding a cache to the original
// brute force recurrence
// Easiest way to apply DP in general
map<int, int> map_dp;
int solve_memo(const vector<int> &h, int N) {
if (map_dp.find(N) != map_dp.end())
return map_dp[N];
if (N < 0)
return INF;
if (N == 0)
return 0;
return min(solve_memo(h, N - 1) + abs(h[N] - h[N - 1]),
solve_memo(h, N - 2) + abs(h[N] - h[N - 2]));
}
// Same idea as last time
// Instead of doing it top down, we will do it bottom up
// Building up smaller values of this optimization first and using
// them to find the answer for N
// This is just changing the order
// You need to know the order of your computations for this to work.
// This case is easy. Generally this means topologically sorting your
// computations
// If this is hard, you may just want to do something like solve_memo.
int solve_tab(const vector<int> &h, int N) {
vector<int> dp(N);
// Initial conditions
dp[0] = 0;
// This is here because so
// the recurrence doesn't reach too
// far back with indices
dp[1] = abs(h[0] - h[1]);
// Original recurrence
for (int i = 2; i <= N; ++i) {
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
}
return dp[N - 1];
}
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int N;
cin >> N;
vector<int> h(N);
for (auto &e : h) {
cin >> e;
}
// cout << solve_backwards(h, N - 1) << '\n';
// cout << solve_forwards(h, 0) << '\n';
cout << solve_memo(h, N - 1) << '\n';
// cout << solve_tab(h, N) << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define INF (int)(1e9)
// The recurrence we will be optimizing is
// c(n) = min(c(n - 1) + cost(n, n - 1),
// c(n - 2) + cost(n, n - 2))
// h[i] is the "value" of stone i
// cost(i, j) = abs(h[i] - h[j])
// I think this way is more natural
int solve_backwards(const vector<int> &h, int N) {
if (N < 0)
return INF;
if (N == 0)
return 0;
return min(solve_backwards(h, N - 1) + abs(h[N] - h[N - 1]),
solve_backwards(h, N - 2) + abs(h[N] - h[N - 2]));
}
int solve_forwards(const vector<int> &h, int N) {
if ((size_t)N >= h.size())
return INF;
if ((size_t)N == h.size() - 1)
return 0;
return min(solve_forwards(h, N + 1) + abs(h[N] - h[N + 1]),
solve_forwards(h, N + 2) + abs(h[N] - h[N + 2]));
}
// position -> cost
// the shortest path to i will inform us about the shortest
// path to get to i + 1 and i + 2
// this will solve to the shortest path to N in general
// This is really just adding a cache to the original
// brute force recurrence
// Easiest way to apply DP in general
map<int, int> map_dp;
int solve_memo(const vector<int> &h, int N) {
if (map_dp.find(N) != map_dp.end())
return map_dp[N];
if (N < 0)
return INF;
if (N == 0)
return 0;
return map_dp[N] = min(solve_memo(h, N - 1) + abs(h[N] - h[N - 1]),
solve_memo(h, N - 2) + abs(h[N] - h[N - 2]));
}
// Same idea as last time
// Instead of doing it top down, we will do it bottom up
// Building up smaller values of this optimization first and using
// them to find the answer for N
// This is just changing the order
// You need to know the order of your computations for this to work.
// This case is easy. Generally this means topologically sorting your
// computations
// If this is hard, you may just want to do something like solve_memo.
int solve_tab(const vector<int> &h, int N) {
vector<int> dp(N);
// Initial conditions
dp[0] = 0;
// This is here because so
// the recurrence doesn't reach too
// far back with indices
dp[1] = abs(h[0] - h[1]);
// Original recurrence
for (int i = 2; i <= N; ++i) {
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
}
return dp[N - 1];
}
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int N;
cin >> N;
vector<int> h(N);
for (auto &e : h) {
cin >> e;
}
// cout << solve_backwards(h, N - 1) << '\n';
// cout << solve_forwards(h, 0) << '\n';
cout << solve_memo(h, N - 1) << '\n';
// cout << solve_tab(h, N) << '\n';
return 0;
}
|
replace
| 51 | 53 | 51 | 53 |
TLE
| |
p03160
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define reps(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define rreps(i, x) for (ll i = (ll)(x); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll, ll>>
#define vpi vector<pair<int, int>>
#define mod 1000000007
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
int h[10000];
int dp[10001];
int main() {
int n;
cin >> n;
rep(i, n) cin >> h[i];
int INF = 1 << 30;
reps(i, n) dp[i] = INF;
dp[0] = 0;
dp[1] = abs(h[1] - h[0]);
for (int i = 2; i < n; i++) {
chmin(dp[i], dp[i - 1] + abs(h[i - 1] - h[i]));
chmin(dp[i], dp[i - 2] + abs(h[i - 2] - h[i]));
}
cout << dp[n - 1] << endl;
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define reps(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define rreps(i, x) for (ll i = (ll)(x); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll, ll>>
#define vpi vector<pair<int, int>>
#define mod 1000000007
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
int h[100000];
int dp[100001];
int main() {
int n;
cin >> n;
rep(i, n) cin >> h[i];
int INF = 1 << 30;
reps(i, n) dp[i] = INF;
dp[0] = 0;
dp[1] = abs(h[1] - h[0]);
for (int i = 2; i < n; i++) {
chmin(dp[i], dp[i - 1] + abs(h[i - 1] - h[i]));
chmin(dp[i], dp[i - 2] + abs(h[i - 2] - h[i]));
}
cout << dp[n - 1] << endl;
return 0;
}
|
replace
| 44 | 46 | 44 | 46 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int num_stones;
vector<int> height(10000);
vector<int> cost(10000);
cin >> num_stones;
for (int i = 0; i < num_stones; i++)
cin >> height[i];
cost[0] = 0;
cost[1] = abs(height[1] - height[0]);
for (int i = 2; i < num_stones; i++) {
cost[i] = min(cost[i - 1] + abs(height[i - 1] - height[i]),
cost[i - 2] + abs(height[i - 2] - height[i]));
}
cout << cost[num_stones - 1];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int num_stones;
vector<int> height(1000000);
vector<int> cost(1000000);
cin >> num_stones;
for (int i = 0; i < num_stones; i++)
cin >> height[i];
cost[0] = 0;
cost[1] = abs(height[1] - height[0]);
for (int i = 2; i < num_stones; i++) {
cost[i] = min(cost[i - 1] + abs(height[i - 1] - height[i]),
cost[i - 2] + abs(height[i - 2] - height[i]));
}
cout << cost[num_stones - 1];
return 0;
}
|
replace
| 6 | 8 | 6 | 8 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> ht(n, 0);
for (int i = 0; i < n; ++i) {
cin >> ht[i];
}
std::vector<int> cost(n);
cost[0] = 0;
cost[1] = abs(ht[0] - ht[1]);
for (int i = 2; i < n; ++i) {
cost[i] = min(abs(ht[i] - ht[i - 2]) + cost[i - 2],
abs(ht[i] - ht[i - 1]) + cost[i - 1]);
}
cout << cost[n - 1];
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.text", "r", stdin);
freopen("output.text", "w", stdout);
#endif
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> ht(n, 0);
for (int i = 0; i < n; ++i) {
cin >> ht[i];
}
std::vector<int> cost(n);
cost[0] = 0;
cost[1] = abs(ht[0] - ht[1]);
for (int i = 2; i < n; ++i) {
cost[i] = min(abs(ht[i] - ht[i - 2]) + cost[i - 2],
abs(ht[i] - ht[i - 1]) + cost[i - 1]);
}
cout << cost[n - 1];
}
int main() {
solve();
return 0;
}
|
delete
| 20 | 24 | 20 | 20 |
0
| |
p03160
|
C++
|
Runtime Error
|
// JAI SHREE RAM
typedef long long int ll;
typedef unsigned long long int ull;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define FOR(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define loop for (int i = 0; i < n; i++)
#define max3(a, b, c) max(a, max(b, c))
#define max4(a, b, c, d) max3(a, max(b, c), d)
#define max5(a, b, c, d, e) max4(a, max(b, c), d, e)
#define min3(a, b, c) min(a, min(b, c))
#define min4(a, b, c, d) min3(a, min(b, c), d)
#define min5(a, b, c, d, e) min4(a, min(b, c), d, e)
#define sec second
#define fir first
// #define all(a) (a).begin(),(a).end()
#define vec vector<int>
#define M_PI 3.14159265358979323846 /* pi */
#define pb push_back
#define pii pair<int, int>
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
std::vector<ll> v;
ll n;
std::vector<ll> memo(100005, -1);
ll dp(ll i) {
if (i == 0)
return 0;
if (i == 1)
return abs(v[1] - v[0]);
if (memo[i] == -1)
return memo[i] = min(dp(i - 1) + abs(v[i] - v[i - 1]),
dp(i - 2) + abs(v[i] - v[i - 2]));
else
return memo[i];
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast cin >> n;
FOR(i, n) {
ll x;
cin >> x;
v.pb(x);
}
cout << dp(n - 1);
return 0;
}
|
// JAI SHREE RAM
typedef long long int ll;
typedef unsigned long long int ull;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define FOR(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define loop for (int i = 0; i < n; i++)
#define max3(a, b, c) max(a, max(b, c))
#define max4(a, b, c, d) max3(a, max(b, c), d)
#define max5(a, b, c, d, e) max4(a, max(b, c), d, e)
#define min3(a, b, c) min(a, min(b, c))
#define min4(a, b, c, d) min3(a, min(b, c), d)
#define min5(a, b, c, d, e) min4(a, min(b, c), d, e)
#define sec second
#define fir first
// #define all(a) (a).begin(),(a).end()
#define vec vector<int>
#define M_PI 3.14159265358979323846 /* pi */
#define pb push_back
#define pii pair<int, int>
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
std::vector<ll> v;
ll n;
std::vector<ll> memo(100005, -1);
ll dp(ll i) {
if (i == 0)
return 0;
if (i == 1)
return abs(v[1] - v[0]);
if (memo[i] == -1)
return memo[i] = min(dp(i - 1) + abs(v[i] - v[i - 1]),
dp(i - 2) + abs(v[i] - v[i - 2]));
else
return memo[i];
}
int main() {
fast cin >> n;
FOR(i, n) {
ll x;
cin >> x;
v.pb(x);
}
cout << dp(n - 1);
return 0;
}
|
replace
| 45 | 49 | 45 | 46 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 20010;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int h[maxn], dp[maxn], n;
int main() {
n = read();
for (int i = 1; i <= n; i++)
h[i] = read();
dp[0] = 0;
dp[1] = 0;
dp[2] = abs(h[2] - h[1]);
for (int i = 3; i <= n; i++)
dp[i] =
min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
cout << dp[n] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int h[maxn], dp[maxn], n;
int main() {
n = read();
for (int i = 1; i <= n; i++)
h[i] = read();
dp[0] = 0;
dp[1] = 0;
dp[2] = abs(h[2] - h[1]);
for (int i = 3; i <= n; i++)
dp[i] =
min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
cout << dp[n] << endl;
return 0;
}
|
replace
| 2 | 3 | 2 | 3 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define REP(i, n) for (lint i{}, i##_len = (n); i < i##_len; ++i)
#define DOUBLE_LOOP(i, h, j, w) \
for (lint i{}; i < (lint)(h); ++i) \
for (lint j{}; j < (lint)(w); ++j)
#define DOUBLE_LOOP2(i, j, n) \
for (lint i{}; i < (lint)(n - 1); ++i) \
for (lint j{i + 1}; j < (lint)(n); ++j)
#define SZ(x) ((lint)(x).size())
using lint = long long;
lint N, H, W;
using namespace std;
const long long INF{1LL << 60};
const long double PI{3.1415926535897932};
const long long NUM97{1000000007};
template <class T> inline bool chmax(T &x, T y) {
if (x < y) {
x = y;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &x, T y) {
if (x > y) {
x = y;
return 1;
}
return 0;
}
std::vector<std::string> field;
std::vector<std::vector<bool>> seen(H, std::vector<bool>(W));
const std::vector<int> dx{1, 0, -1, 0};
const std::vector<int> dy{0, 1, 0, -1};
std::vector<lint> dp;
std::vector<lint> h;
int main() {
std::cin >> N;
h.resize(N);
for (auto &r : h)
std::cin >> r;
for (auto &r : dp)
r = INF;
dp[0] = 0;
for (int i = 1; i < N; ++i) {
chmin(dp[i], dp[i - 1] + std::abs(h[i] - h[i - 1]));
if (i > 1) {
chmin(dp[i], dp[i - 2] + std::abs(h[i] - h[i - 2]));
}
}
std::cout << dp[N - 1] << std::endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define REP(i, n) for (lint i{}, i##_len = (n); i < i##_len; ++i)
#define DOUBLE_LOOP(i, h, j, w) \
for (lint i{}; i < (lint)(h); ++i) \
for (lint j{}; j < (lint)(w); ++j)
#define DOUBLE_LOOP2(i, j, n) \
for (lint i{}; i < (lint)(n - 1); ++i) \
for (lint j{i + 1}; j < (lint)(n); ++j)
#define SZ(x) ((lint)(x).size())
using lint = long long;
lint N, H, W;
using namespace std;
const long long INF{1LL << 60};
const long double PI{3.1415926535897932};
const long long NUM97{1000000007};
template <class T> inline bool chmax(T &x, T y) {
if (x < y) {
x = y;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &x, T y) {
if (x > y) {
x = y;
return 1;
}
return 0;
}
std::vector<std::string> field;
std::vector<std::vector<bool>> seen(H, std::vector<bool>(W));
const std::vector<int> dx{1, 0, -1, 0};
const std::vector<int> dy{0, 1, 0, -1};
std::vector<lint> dp;
std::vector<lint> h;
int main() {
std::cin >> N;
h.resize(N);
for (auto &r : h)
std::cin >> r;
dp.resize(N);
for (auto &r : dp)
r = INF;
dp[0] = 0;
for (int i = 1; i < N; ++i) {
chmin(dp[i], dp[i - 1] + std::abs(h[i] - h[i - 1]));
if (i > 1) {
chmin(dp[i], dp[i - 2] + std::abs(h[i] - h[i - 2]));
}
}
std::cout << dp[N - 1] << std::endl;
return 0;
}
|
insert
| 50 | 50 | 50 | 51 |
-11
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#if __has_include("print.hpp")
#include "print.hpp"
#endif
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef pair<int, int> p;
vector<int> dp(10, 0);
vector<int> v;
int n;
void dfs() {
for (int i = 2; i < n; i++) {
dp[i] =
min(dp[i - 1] + abs(v[i - 1] - v[i]), dp[i - 2] + abs(v[i - 2] - v[i]));
}
// print(v);
// print(dp);
cout << dp[n - 1] << endl;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
v.push_back(tmp);
}
dp[0] = 0;
dp[1] = abs(v[0] - v[1]);
dfs();
}
|
#include <bits/stdc++.h>
using namespace std;
#if __has_include("print.hpp")
#include "print.hpp"
#endif
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef pair<int, int> p;
vector<int> dp(100500, 0);
vector<int> v;
int n;
void dfs() {
for (int i = 2; i < n; i++) {
dp[i] =
min(dp[i - 1] + abs(v[i - 1] - v[i]), dp[i - 2] + abs(v[i - 2] - v[i]));
}
// print(v);
// print(dp);
cout << dp[n - 1] << endl;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
v.push_back(tmp);
}
dp[0] = 0;
dp[1] = abs(v[0] - v[1]);
dfs();
}
|
replace
| 13 | 14 | 13 | 14 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize "03"
#pragma GCC target("sse4")
#define ll long long int
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define FRE \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
#define f(i, n) for (ll i = 0; i < n; i++)
#define fa(i, a, n) \
for (ll i = a; a < n ? i < n : i >= n; a < n ? i += 1 : i -= 1)
#define loop(i, a, n) for (ll i = a; i <= n; i++)
#define loopb(i, a, n) for (ll i = a; i >= n; i--)
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define setmem(x, k) memset(x, k, sizeof(x))
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define MOD 1000000007
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
// const ll N = 1e6+5;
// ll a[N], b[N], dp[N], in[N], out[N], level[N], vis[N];
// vl g[N];
ll n, m;
ll dp[100005];
vector<ll> a;
ll fun(vector<ll> a, ll pos) {
if (pos == n - 1) {
return 0;
}
if (pos >= n) {
return INT_MAX;
}
if (dp[pos] != -1)
return dp[pos];
return dp[pos] = min(abs(a[pos] - a[pos + 1]) + fun(a, pos + 1),
abs(a[pos] - a[pos + 2]) + fun(a, pos + 2));
}
void solve() {
// ll k, x, y, p, q, r;
cin >> n;
a.resize(n);
f(i, n) cin >> a[i];
setmem(dp, -1);
cout << fun(a, 0);
}
int32_t main() {
IOS ll T;
// cin >> T;
// while(T--)
solve();
cerr << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << "ms"
<< '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize "03"
#pragma GCC target("sse4")
#define ll long long int
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define FRE \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
#define f(i, n) for (ll i = 0; i < n; i++)
#define fa(i, a, n) \
for (ll i = a; a < n ? i < n : i >= n; a < n ? i += 1 : i -= 1)
#define loop(i, a, n) for (ll i = a; i <= n; i++)
#define loopb(i, a, n) for (ll i = a; i >= n; i--)
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define setmem(x, k) memset(x, k, sizeof(x))
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define MOD 1000000007
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
// const ll N = 1e6+5;
// ll a[N], b[N], dp[N], in[N], out[N], level[N], vis[N];
// vl g[N];
ll n, m;
ll dp[100005];
vector<ll> a;
ll fun(vector<ll> &a, ll pos) {
if (pos == n - 1) {
return 0;
}
if (pos >= n) {
return INT_MAX;
}
if (dp[pos] != -1)
return dp[pos];
return dp[pos] = min(abs(a[pos] - a[pos + 1]) + fun(a, pos + 1),
abs(a[pos] - a[pos + 2]) + fun(a, pos + 2));
}
void solve() {
// ll k, x, y, p, q, r;
cin >> n;
a.resize(n);
f(i, n) cin >> a[i];
setmem(dp, -1);
cout << fun(a, 0);
}
int32_t main() {
IOS ll T;
// cin >> T;
// while(T--)
solve();
cerr << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << "ms"
<< '\n';
return 0;
}
|
replace
| 45 | 46 | 45 | 46 |
0
|
Time elapsed : 36.11ms
|
p03160
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#include <utility>
#define ll long long
#define fr first
#define sd second
using namespace std;
struct Node {
int data;
struct Node *left;
struct Node *right;
Node(int x) {
data = x;
left = NULL;
right = NULL;
}
};
#define Node struct Node
int dp[100005];
int calc(int a[], int i) {
if (i == 0)
return 0;
if (i == 1)
return abs(a[1] - a[0]);
return min(abs(a[i] - a[i - 1]) + calc(a, i - 1),
abs(a[i] - a[i - 2]) + calc(a, i - 2));
}
int main() {
/*freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);*/
int t = 1;
// cin>>t;
while (t--) {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
memset(dp, -1, sizeof(dp));
cout << calc(a, n - 1) << endl;
}
}
|
#include <bits/stdc++.h>
#include <utility>
#define ll long long
#define fr first
#define sd second
using namespace std;
struct Node {
int data;
struct Node *left;
struct Node *right;
Node(int x) {
data = x;
left = NULL;
right = NULL;
}
};
#define Node struct Node
int dp[100005];
int calc(int a[], int i) {
if (i == 0)
return 0;
if (i == 1)
return abs(a[1] - a[0]);
if (dp[i] != -1)
return dp[i];
return dp[i] = min(abs(a[i] - a[i - 1]) + calc(a, i - 1),
abs(a[i] - a[i - 2]) + calc(a, i - 2));
}
int main() {
/*freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);*/
int t = 1;
// cin>>t;
while (t--) {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
memset(dp, -1, sizeof(dp));
cout << calc(a, n - 1) << endl;
}
}
|
replace
| 27 | 29 | 27 | 31 |
TLE
| |
p03160
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INF 1000000000000
using namespace std;
using ll = long long;
int main() {
ll n;
cin >> n;
vector<ll> h(n);
ll dp[10010];
for (ll i = 0; i < n; i++) {
cin >> h[i];
}
dp[0] = 0;
dp[1] = abs(h[0] - h[1]);
for (ll i = 2; i < n; i++) {
dp[i] =
min(dp[i - 2] + abs(h[i - 2] - h[i]), dp[i - 1] + abs(h[i - 1] - h[i]));
}
cout << dp[n - 1] << endl;
}
|
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INF 1000000000000
using namespace std;
using ll = long long;
int main() {
ll n;
cin >> n;
vector<ll> h(n);
ll dp[100010];
for (ll i = 0; i < n; i++) {
cin >> h[i];
}
dp[0] = 0;
dp[1] = abs(h[0] - h[1]);
for (ll i = 2; i < n; i++) {
dp[i] =
min(dp[i - 2] + abs(h[i - 2] - h[i]), dp[i - 1] + abs(h[i - 1] - h[i]));
}
cout << dp[n - 1] << endl;
}
|
replace
| 19 | 20 | 19 | 20 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n), dp(n);
for (int i = 0; i < n; i++)
cin >> v[i];
dp[0] = 0;
for (int i = 1; i <= n; i++)
dp[i] = INT_MAX;
for (int i = 0; i < n; i++) {
if (i + 1 < n)
dp[i + 1] = min(dp[i + 1], dp[i] + abs(v[i] - v[i + 1]));
if (i + 2 < n)
dp[i + 2] = min(dp[i + 2], dp[i] + abs(v[i] - v[i + 2]));
}
cout << dp[n - 1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n), dp(n + 1);
for (int i = 0; i < n; i++)
cin >> v[i];
dp[0] = 0;
for (int i = 1; i <= n; i++)
dp[i] = INT_MAX;
for (int i = 0; i < n; i++) {
if (i + 1 < n)
dp[i + 1] = min(dp[i + 1], dp[i] + abs(v[i] - v[i + 1]));
if (i + 2 < n)
dp[i + 2] = min(dp[i + 2], dp[i] + abs(v[i] - v[i + 2]));
}
cout << dp[n - 1] << endl;
return 0;
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <iostream>
#define int long long
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
// const int MOD = 10e9+7;
const int INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
signed main() {
int N;
cin >> N;
int h[N];
int dp[10100];
REP(i, N) cin >> h[i];
fill(dp, dp + N, INF);
dp[0] = 0;
REP(i, N) {
// dp[i]はi+1番目のところに行きつくまでの最短コスト
if (i + 1 <= N)
dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
if (i + 2 <= N)
dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
}
cout << dp[N - 1] << endl;
}
|
#include <iostream>
#define int long long
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
// const int MOD = 10e9+7;
const int INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
signed main() {
int N;
cin >> N;
int h[N];
int dp[100100];
REP(i, N) cin >> h[i];
fill(dp, dp + N, INF);
dp[0] = 0;
REP(i, N) {
// dp[i]はi+1番目のところに行きつくまでの最短コスト
if (i + 1 <= N)
dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
if (i + 2 <= N)
dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
}
cout << dp[N - 1] << endl;
}
|
replace
| 27 | 28 | 27 | 28 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <cstdio>
int h[10010];
int ans[10010];
int cost(int a, int b) {
int ret = a - b;
return ret >= 0 ? ret : -ret;
}
int min(int a, int b) { return a < b ? a : b; }
int main() {
int n;
while (scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; i++) {
scanf("%d", &h[i]);
}
ans[2] = cost(h[1], h[2]);
ans[3] = min(cost(h[1], h[3]), ans[2] + cost(h[2], h[3]));
for (int i = 4; i <= n; i++) {
ans[i] = min(ans[i - 2] + cost(h[i - 2], h[i]),
ans[i - 1] + cost(h[i - 1], h[i]));
}
printf("%d\n", ans[n]);
}
return 0;
}
|
#include <cstdio>
int h[100100];
int ans[100100];
int cost(int a, int b) {
int ret = a - b;
return ret >= 0 ? ret : -ret;
}
int min(int a, int b) { return a < b ? a : b; }
int main() {
int n;
while (scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; i++) {
scanf("%d", &h[i]);
}
ans[2] = cost(h[1], h[2]);
ans[3] = min(cost(h[1], h[3]), ans[2] + cost(h[2], h[3]));
for (int i = 4; i <= n; i++) {
ans[i] = min(ans[i - 2] + cost(h[i - 2], h[i]),
ans[i - 1] + cost(h[i - 1], h[i]));
}
printf("%d\n", ans[n]);
}
return 0;
}
|
replace
| 1 | 3 | 1 | 3 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> h(N);
for (int i = 0; i < N; i++)
cin >> h[i];
static int dp[1000000000];
dp[0] = 0;
dp[1] = abs(h[0] - h[1]);
for (int i = 2; i < N; i++) {
dp[i] =
min(dp[i - 2] + abs(h[i - 2] - h[i]), dp[i - 1] + abs(h[i - 1] - h[i]));
}
cout << dp[N - 1] << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> h(N);
for (int i = 0; i < N; i++)
cin >> h[i];
int dp[1000000];
dp[0] = 0;
dp[1] = abs(h[0] - h[1]);
for (int i = 2; i < N; i++) {
dp[i] =
min(dp[i - 2] + abs(h[i - 2] - h[i]), dp[i - 1] + abs(h[i - 1] - h[i]));
}
cout << dp[N - 1] << endl;
return 0;
}
|
replace
| 13 | 14 | 13 | 14 |
-11
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define M_DEBUG if (1)
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define optimize_cin() \
cin.tie(0); \
ios::sync_with_stdio(false)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
using lint = long long;
typedef unsigned long long int ullint;
/******************************************************************************
Main
******************************************************************************/
#define L_MAX_STEPS 10000
int main() {
int n = 0;
cin >> n;
assert(n >= 2 && n <= pow(10, 5));
int steps[L_MAX_STEPS] = {0}; // 第 i + 1 足場の高さ
int costs[L_MAX_STEPS] = {0}; // 第 i + 1 足場までの最小コスト。
rep(i, n) {
cin >> steps[i];
assert(steps[i] >= 1 && steps[i] <= pow(10, 4));
if (i == 0)
continue;
// 0 - i までの最小コストを調べたい
// i - 1 から飛んでくるのと、i - 2 から飛ぶのと、どっちがローコストか?
int cost_best = abs(steps[i] - steps[i - 1]);
if (i > 1) {
cost_best += costs[i - 1];
int cost = abs(steps[i] - steps[i - 2]);
cost += costs[i - 2];
cost_best = (cost_best > cost) ? cost : cost_best;
}
costs[i] = cost_best;
}
cout << costs[n - 1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define M_DEBUG if (1)
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define optimize_cin() \
cin.tie(0); \
ios::sync_with_stdio(false)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
using lint = long long;
typedef unsigned long long int ullint;
/******************************************************************************
Main
******************************************************************************/
#define L_MAX_STEPS 100000
int main() {
int n = 0;
cin >> n;
assert(n >= 2 && n <= pow(10, 5));
int steps[L_MAX_STEPS] = {0}; // 第 i + 1 足場の高さ
int costs[L_MAX_STEPS] = {0}; // 第 i + 1 足場までの最小コスト。
rep(i, n) {
cin >> steps[i];
assert(steps[i] >= 1 && steps[i] <= pow(10, 4));
if (i == 0)
continue;
// 0 - i までの最小コストを調べたい
// i - 1 から飛んでくるのと、i - 2 から飛ぶのと、どっちがローコストか?
int cost_best = abs(steps[i] - steps[i - 1]);
if (i > 1) {
cost_best += costs[i - 1];
int cost = abs(steps[i] - steps[i - 2]);
cost += costs[i - 2];
cost_best = (cost_best > cost) ? cost : cost_best;
}
costs[i] = cost_best;
}
cout << costs[n - 1] << endl;
return 0;
}
|
replace
| 38 | 39 | 38 | 39 |
0
| |
p03160
|
C++
|
Runtime Error
|
/*
███╗ ███╗ █████╗ ███████╗███╗ ███╗ ██████╗ ██╗
██╗██████╗ ███████╗ █████╗ ███╗ ███╗██████╗ ██╗ ██╗ ████╗
████║██╔══██╗╚════██║████╗ ████║██╔═══██╗██║ ██║██╔══██╗╚════██║██╔══██╗████╗
████║██╔══██╗╚██╗ ██╔╝ ██╔████╔██║███████║ ██╔╝██╔████╔██║██║ ██║██║
██║██║ ██║ ██╔╝███████║██╔████╔██║██║ ██║ ╚████╔╝ ██║╚██╔╝██║██╔══██║
██╔╝ ██║╚██╔╝██║██║ ██║██║ ██║██║ ██║ ██╔╝ ██╔══██║██║╚██╔╝██║██║ ██║
╚██╔╝ ██║ ╚═╝ ██║██║ ██║ ██║ ██║ ╚═╝ ██║╚██████╔╝╚██████╔╝██████╔╝██╗██║
██║ ██║██║ ╚═╝ ██║██████╔╝ ██║ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
╚═════╝ ╚═════╝ ╚═════╝ ╚═╝╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝
“Nobody but you have to believe in your dreams to make
them a reality.” ― Germany Kent
*/
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define Ma7moud_7amdy \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define Open_Sesame Open()
#define pb push_back
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define sz(v) ((int)((v).size()))
#define clr(arr, x) memset(arr, x, sizeof arr)
#define endl "\n"
#define Accepted 0
#define watch(x) cout << #x << " = " << x << endl;
#define un_map unordered_map
#define RT(x) return cout << (x), 0;
#define sc(a) scanf("%d", &a)
#define scll(x) scanf("%I64d", &x)
#define scan(s) scanf("%[^\n]%*c", &s)
#define pr(s) printf("%s", s.c_str()); // print string
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double EPS = -1e-2;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const ll mod = 1000000007;
const int Mx = INT_MAX;
const int Mn = INT_MIN;
const ll MX = LLONG_MAX;
const ll MN = LLONG_MIN;
const int N = 1e5 + 1;
void Open() {
#ifndef ONLINE_JUDGE
freopen("Input.txt", "r", stdin);
freopen("Output.txt", "w", stdout);
#endif
}
int n, k;
int mem[N];
vector<int> v;
int solve(int i) {
int &ret = mem[i];
if (~ret)
return ret;
ret = Mx;
if (i + 1 < n)
ret = min(ret, solve(i + 1) + abs(v[i] - v[i + 1]));
if (i + 2 < n)
ret = min(ret, solve(i + 2) + abs(v[i] - v[i + 2]));
ret = ret == Mx ? 0 : ret;
return ret;
}
int main() {
Ma7moud_7amdy;
Open_Sesame;
clr(mem, -1);
cin >> n;
v = vector<int>(n);
for (int i = 0; i < n; i++)
cin >> v[i];
cout << solve(0);
return Accepted;
}
|
/*
███╗ ███╗ █████╗ ███████╗███╗ ███╗ ██████╗ ██╗
██╗██████╗ ███████╗ █████╗ ███╗ ███╗██████╗ ██╗ ██╗ ████╗
████║██╔══██╗╚════██║████╗ ████║██╔═══██╗██║ ██║██╔══██╗╚════██║██╔══██╗████╗
████║██╔══██╗╚██╗ ██╔╝ ██╔████╔██║███████║ ██╔╝██╔████╔██║██║ ██║██║
██║██║ ██║ ██╔╝███████║██╔████╔██║██║ ██║ ╚████╔╝ ██║╚██╔╝██║██╔══██║
██╔╝ ██║╚██╔╝██║██║ ██║██║ ██║██║ ██║ ██╔╝ ██╔══██║██║╚██╔╝██║██║ ██║
╚██╔╝ ██║ ╚═╝ ██║██║ ██║ ██║ ██║ ╚═╝ ██║╚██████╔╝╚██████╔╝██████╔╝██╗██║
██║ ██║██║ ╚═╝ ██║██████╔╝ ██║ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
╚═════╝ ╚═════╝ ╚═════╝ ╚═╝╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝
“Nobody but you have to believe in your dreams to make
them a reality.” ― Germany Kent
*/
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define Ma7moud_7amdy \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define Open_Sesame Open()
#define pb push_back
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define sz(v) ((int)((v).size()))
#define clr(arr, x) memset(arr, x, sizeof arr)
#define endl "\n"
#define Accepted 0
#define watch(x) cout << #x << " = " << x << endl;
#define un_map unordered_map
#define RT(x) return cout << (x), 0;
#define sc(a) scanf("%d", &a)
#define scll(x) scanf("%I64d", &x)
#define scan(s) scanf("%[^\n]%*c", &s)
#define pr(s) printf("%s", s.c_str()); // print string
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double EPS = -1e-2;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const ll mod = 1000000007;
const int Mx = INT_MAX;
const int Mn = INT_MIN;
const ll MX = LLONG_MAX;
const ll MN = LLONG_MIN;
const int N = 1e5 + 1;
void Open() {
#ifndef ONLINE_JUDGE
freopen("Input.txt", "r", stdin);
freopen("Output.txt", "w", stdout);
#endif
}
int n, k;
int mem[N];
vector<int> v;
int solve(int i) {
int &ret = mem[i];
if (~ret)
return ret;
ret = Mx;
if (i + 1 < n)
ret = min(ret, solve(i + 1) + abs(v[i] - v[i + 1]));
if (i + 2 < n)
ret = min(ret, solve(i + 2) + abs(v[i] - v[i + 2]));
ret = ret == Mx ? 0 : ret;
return ret;
}
int main() {
Ma7moud_7amdy;
// Open_Sesame;
clr(mem, -1);
cin >> n;
v = vector<int>(n);
for (int i = 0; i < n; i++)
cin >> v[i];
cout << solve(0);
return Accepted;
}
|
replace
| 71 | 72 | 71 | 72 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define watchArray(v) \
for (auto i : v) \
cout << i << " "; \
cout << endl;
#define all(v) (v).begin(), (v).end()
#define endl '\n'
#define MAX 200000
#define MOD 100000007
#define INF numeric_limits<int>::max()
#define INFLL numeric_limits<long long int>::max()
typedef long long int lli;
typedef long double ld;
int n;
vector<int> memo, v;
int main(void) {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
memo.assign(n, INF);
v.resize(n);
for (auto &i : v)
cin >> i;
memo[0] = 0;
memo[1] = abs(v[0] - v[1]);
for (int i = 2; i < v.size(); i++) {
memo[i] = min(memo[i - 1] + abs(v[i] - v[i - 1]),
memo[i - 2] + abs(v[i] - v[i - 2]));
}
cout << memo[n - 1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define watchArray(v) \
for (auto i : v) \
cout << i << " "; \
cout << endl;
#define all(v) (v).begin(), (v).end()
#define endl '\n'
#define MAX 200000
#define MOD 100000007
#define INF numeric_limits<int>::max()
#define INFLL numeric_limits<long long int>::max()
typedef long long int lli;
typedef long double ld;
int n;
vector<int> memo, v;
int main(void) {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
memo.assign(n, INF);
v.resize(n);
for (auto &i : v)
cin >> i;
memo[0] = 0;
memo[1] = abs(v[0] - v[1]);
for (int i = 2; i < v.size(); i++) {
memo[i] = min(memo[i - 1] + abs(v[i] - v[i - 1]),
memo[i - 2] + abs(v[i] - v[i - 2]));
}
cout << memo[n - 1] << endl;
return 0;
}
|
replace
| 24 | 28 | 24 | 28 |
-11
| |
p03160
|
C++
|
Runtime Error
|
// 1.read question_2.read I/O_3.read test cases_4.read constraints(to decide TC
// of solution)_5.decide method_6.dry run_ 7.code_8.test_9.submit
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define mod 1000000007
#define F first
#define S second
#define _READ freopen("input.txt", "r", stdin);
#define pb push_back
#define MP make_pair
#define _FAST \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
int main() {
#ifndef ONLINE_JUDGE
_READ
#endif
_FAST
lli n, t, i, j, k, ans = 0, flag = 0, a, b, m;
cin >> n;
vector<lli> ar(n);
for (auto &i : ar)
cin >> i;
vector<lli> dp(n, 0);
for (i = 1; i < n; i++)
dp[i] = min(abs(ar[i - 1] - ar[i]) + dp[i - 1],
i - 2 < 0 ? INT_MAX : abs(ar[i - 2] - ar[i]) + dp[i - 2]);
cout << dp[n - 1];
return 0;
}
|
// 1.read question_2.read I/O_3.read test cases_4.read constraints(to decide TC
// of solution)_5.decide method_6.dry run_ 7.code_8.test_9.submit
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define mod 1000000007
#define F first
#define S second
#define _READ freopen("input.txt", "r", stdin);
#define pb push_back
#define MP make_pair
#define _FAST \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
int main() {
_FAST
lli n, t, i, j, k, ans = 0, flag = 0, a, b, m;
cin >> n;
vector<lli> ar(n);
for (auto &i : ar)
cin >> i;
vector<lli> dp(n, 0);
for (i = 1; i < n; i++)
dp[i] = min(abs(ar[i - 1] - ar[i]) + dp[i - 1],
i - 2 < 0 ? INT_MAX : abs(ar[i - 2] - ar[i]) + dp[i - 2]);
cout << dp[n - 1];
return 0;
}
|
replace
| 16 | 19 | 16 | 17 |
-6
|
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03160
|
C++
|
Runtime Error
|
// #include<bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
int dp[n];
dp[0] = 0;
dp[1] = abs(arr[0] - arr[1]);
for (int i = 2; i < n; i++) {
dp[i] = min(dp[i - 1] + abs(arr[i] - arr[i - 1]),
dp[i - 2] + abs(arr[i] - arr[i - 2]));
}
// cout << dp[n-1];
return dp[n - 1];
}
|
// #include<bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
int dp[n];
dp[0] = 0;
dp[1] = abs(arr[0] - arr[1]);
for (int i = 2; i < n; i++) {
dp[i] = min(dp[i - 1] + abs(arr[i] - arr[i - 1]),
dp[i - 2] + abs(arr[i] - arr[i - 2]));
}
cout << dp[n - 1];
return 0;
// return dp[n-1];
}
|
replace
| 16 | 18 | 16 | 19 |
30
| |
p03160
|
C++
|
Runtime Error
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define loopi(x, y) for (int i = x; i < (y); i++)
#define loopj(x, y) for (int j = x; j < (y); j++)
#define newline cout << "\n";
#define ll long long int
using namespace std;
#define mod 1000000007
int cost[1000000];
int jump(vector<int> &ht, int i, int n) {
if (i >= n - 1) {
return 0;
}
int a = INT_MAX, b = INT_MAX;
if (i + 1 < n) {
if (cost[i + 1] == -1) {
cost[i + 1] = jump(ht, i + 1, n);
}
a = abs(ht[i + 1] - ht[i]) + cost[i + 1];
}
if (i + 2 < n) {
if (cost[i + 2] == -1) {
cost[i + 2] = jump(ht, i + 2, n);
}
b = abs(ht[i + 2] - ht[i]) + cost[i + 2];
}
return cost[i] = min(a, b);
}
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
vector<int> ht(n);
loopi(0, n) {
cin >> ht[i];
cost[i] = -1;
}
cout << jump(ht, 0, n);
return 0;
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define loopi(x, y) for (int i = x; i < (y); i++)
#define loopj(x, y) for (int j = x; j < (y); j++)
#define newline cout << "\n";
#define ll long long int
using namespace std;
#define mod 1000000007
int cost[1000000];
int jump(vector<int> &ht, int i, int n) {
if (i >= n - 1) {
return 0;
}
int a = INT_MAX, b = INT_MAX;
if (i + 1 < n) {
if (cost[i + 1] == -1) {
cost[i + 1] = jump(ht, i + 1, n);
}
a = abs(ht[i + 1] - ht[i]) + cost[i + 1];
}
if (i + 2 < n) {
if (cost[i + 2] == -1) {
cost[i + 2] = jump(ht, i + 2, n);
}
b = abs(ht[i + 2] - ht[i]) + cost[i + 2];
}
return cost[i] = min(a, b);
}
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int n;
cin >> n;
vector<int> ht(n);
loopi(0, n) {
cin >> ht[i];
cost[i] = -1;
}
cout << jump(ht, 0, n);
return 0;
}
|
replace
| 44 | 48 | 44 | 48 |
-6
|
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> par;
typedef vector<par> vpar;
#define forn(i, n) for (ll i = 0; i < n; i++)
#define wez(n) \
ll(n); \
cin >> (n);
#define setmax(a, b) (a) = max((a), (b))
#define setmin(a, b) (a) = min((a), (b))
#define pb push_back
#define mp make_pair
#define outa(a, e) forn(i, e) cout << a[i] << (i == e - 1 ? '\n' : ' ')
#define oute(n) cout << n << "\n"
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll n;
cin >> n;
ll dp[n][2];
ll h[n];
forn(i, n) cin >> h[i];
dp[0][1] = 0;
dp[0][2] = 0;
dp[1][2] = 1e9;
dp[1][1] = (h[0] > h[1] ? h[0] - h[1] : h[1] - h[0]);
for (ll i = 2; i < n; i++) {
dp[i][1] = min(dp[i - 1][1], dp[i - 1][2]) +
(h[i] >= h[i - 1] ? h[i] - h[i - 1] : h[i - 1] - h[i]);
dp[i][2] = min(dp[i - 2][1], dp[i - 2][2]) +
(h[i] >= h[i - 2] ? h[i] - h[i - 2] : h[i - 2] - h[i]);
}
cout << min(dp[n - 1][1], dp[n - 1][2]) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> par;
typedef vector<par> vpar;
#define forn(i, n) for (ll i = 0; i < n; i++)
#define wez(n) \
ll(n); \
cin >> (n);
#define setmax(a, b) (a) = max((a), (b))
#define setmin(a, b) (a) = min((a), (b))
#define pb push_back
#define mp make_pair
#define outa(a, e) forn(i, e) cout << a[i] << (i == e - 1 ? '\n' : ' ')
#define oute(n) cout << n << "\n"
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ll n;
cin >> n;
ll dp[n][2];
ll h[n];
forn(i, n) cin >> h[i];
dp[0][1] = 0;
dp[0][2] = 0;
dp[1][2] = 1e9;
dp[1][1] = (h[0] > h[1] ? h[0] - h[1] : h[1] - h[0]);
for (ll i = 2; i < n; i++) {
dp[i][1] = min(dp[i - 1][1], dp[i - 1][2]) +
(h[i] >= h[i - 1] ? h[i] - h[i - 1] : h[i - 1] - h[i]);
dp[i][2] = min(dp[i - 2][1], dp[i - 2][2]) +
(h[i] >= h[i - 2] ? h[i] - h[i - 2] : h[i - 2] - h[i]);
}
cout << min(dp[n - 1][1], dp[n - 1][2]) << endl;
return 0;
}
|
replace
| 24 | 28 | 24 | 28 |
-11
| |
p03160
|
C++
|
Runtime Error
|
/********************************************/ /**
****** Author: Shivam Kejriwal
******************
****** Handle: techno_phyle
******************
***********************************************/
#include <bits/stdc++.h>
using namespace std;
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
typedef long long ll;
#define mod 1000000007
#define N 100010
#define M 200010
#define db(a) cout << a << endl
#define db2(a, b) cout << a << " " << b << endl
#define dbp(a) cout << a.first << " " << a.second << endl
#define adb(a) \
for (auto it : a) \
cout << it << " "; \
cout << endl
#define adbp(a) \
for (auto it : a) \
cout << it.first << " " << it.second << endl
#define pb push_back
#define mp make_pair
typedef pair<double, long> key;
struct comp {
bool operator()(pair<int, int> p1, pair<int, int> p2) {
if (p1.first < p2.first)
return false;
if (p2.first < p1.first)
return true;
return p1.second < p2.second;
};
};
// greater<pair<int,int> , greater<int>>
int main() {
fastIO;
#ifndef ONLINE_JUDGE
freopen("../input.txt", "r", stdin);
freopen("../output.txt", "w", stdout);
#endif
int n;
cin >> n;
int a[n + 1];
for (int i = 1; i <= n; i++)
cin >> a[i];
int dp[n + 1];
dp[1] = 0;
dp[2] = abs(a[2] - a[1]);
for (int i = 3; i <= n; i++) {
dp[i] =
min(abs(a[i] - a[i - 1]) + dp[i - 1], abs(a[i] - a[i - 2]) + dp[i - 2]);
}
cout << dp[n] << endl;
return 0;
}
|
/********************************************/ /**
****** Author: Shivam Kejriwal
******************
****** Handle: techno_phyle
******************
***********************************************/
#include <bits/stdc++.h>
using namespace std;
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
typedef long long ll;
#define mod 1000000007
#define N 100010
#define M 200010
#define db(a) cout << a << endl
#define db2(a, b) cout << a << " " << b << endl
#define dbp(a) cout << a.first << " " << a.second << endl
#define adb(a) \
for (auto it : a) \
cout << it << " "; \
cout << endl
#define adbp(a) \
for (auto it : a) \
cout << it.first << " " << it.second << endl
#define pb push_back
#define mp make_pair
typedef pair<double, long> key;
struct comp {
bool operator()(pair<int, int> p1, pair<int, int> p2) {
if (p1.first < p2.first)
return false;
if (p2.first < p1.first)
return true;
return p1.second < p2.second;
};
};
// greater<pair<int,int> , greater<int>>
int main() {
fastIO;
// #ifndef ONLINE_JUDGE
// freopen("../input.txt", "r", stdin);
// freopen("../output.txt","w",stdout);
// #endif
int n;
cin >> n;
int a[n + 1];
for (int i = 1; i <= n; i++)
cin >> a[i];
int dp[n + 1];
dp[1] = 0;
dp[2] = abs(a[2] - a[1]);
for (int i = 3; i <= n; i++) {
dp[i] =
min(abs(a[i] - a[i - 1]) + dp[i - 1], abs(a[i] - a[i - 2]) + dp[i - 2]);
}
cout << dp[n] << endl;
return 0;
}
|
replace
| 45 | 49 | 45 | 49 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define fi first
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define fit(x) for (auto it = x.begin(); it != x.end(); ++it)
#define se second
#define mp make_pair
#define ALL(x) x.begin(), x.end()
#define ALP "abcdefghijklmnopqrstuvwxyz"
#define nline cout << "\n"
#define rep(i, x) for (i = 0; i < x; ++i)
#define repr(i, a, b) for (i = a; i <= b; ++i)
#define PLL pair<ll, ll>
#define VLL vector<ll>
#define W(t) while (t--)
#define modsum(a, b, M) (a % M + b % M) % M
#define modsub(a, b, M) (a % M - b % M + M) % M
#define modmul(a, b, M) (a % M * b % M) % M
#define moddiv(a, b, M) (a % M * modinv(b, M) % M) % M
#define seperate cout << "*****************\n";
const long long mi2 = 500000004;
const long long mi3 = 333333336;
const long long MOD = 1000000007;
#define ordered_set \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_pset \
tree<PLL, null_type, less<PLL>, rb_tree_tag, \
tree_order_statistics_node_update>
int xcod[4] = {-1, 0, 1, 0};
int ycod[4] = {0, 1, 0, -1};
#define dbg(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
struct HASH {
size_t operator()(const pair<ll, ll> &x) const {
return hash<long long>()(((long long)x.first) ^
(((long long)x.second) << 32));
}
};
// unordered_map<pair<int,int>,int,HASH>mp;
// unordered_map<ll, ll, custom_hash> safe_map;
ll powermod(ll x, ll n, ll M) {
ll result = 1;
while (n > 0) {
if (n % 2 == 1)
result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result;
}
vector<ll> readll() {
cin >> ws;
vector<ll> v;
string input;
getline(cin, input);
cout << input;
istringstream is(input);
ll num;
while (is >> num)
v.pb(num);
return v;
}
/*
int BLOCK_SIZE;
inline bool mo_cmp(const pair< pair<int, int>, int> &x,const pair< pair<int,
int>, int> &y)
{
if ( (x.fi.fi/BLOCK_SIZE) != (y.fi.fi/BLOCK_SIZE) )
return x < y ;
return ((x.fi.fi/BLOCK_SIZE)&1)^(x.fi.se<y.fi.se) ;
}
*/
ll modinv(ll n, ll p) { return powermod(n, p - 2, p); }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll fact[1000005], invf[1000005];
void facmod(ll n, ll M) {
ll i;
fact[0] = fact[1] = 1;
for (i = 2; i <= n; ++i) {
fact[i] = ((fact[i - 1]) % M * (i % M)) % M;
}
invf[n] = modinv(fact[n], M);
for (i = n - 1; i >= 0; --i) {
invf[i] = invf[i + 1] * (i + 1);
invf[i] %= M;
}
}
/*
ll T=0;
ll p[200005], d[200005];
ll tin[200005], tout[200005];
vector<ll> g[200005];
bool vis[200005];
void dfs(ll v,ll par=1,ll dep=0) {
//dbg(v);
tin[v] = T++;
vis[v]=true;
p[v] = par;
d[v] = dep;
for (auto to : g[v]) {
if (vis[to]) continue;
dfs(to,v,dep+1);
}
tout[v] = T++;
}
*/
// ll treeSet() {
// ordered_set o_set;
// o_set.insert(1); //for duplicate elements use pair and use second element
// unique
// // find by order returns iterator of ith largest element;
// cout<<*(o_set.find_by_order(1)) //second smallest element;
// // Finding the number of elements
// // strictly less than k=4
// cout << o_set.order_of_key(4) ;
// // Deleting 2 from the set if it exists
// if (o_set.find(2) != o_set.end())
// o_set.erase(o_set.find(2));
// }
void solve() {
ll i, n;
cin >> n;
ll h[n + 4], cst[n + 4];
rep(i, n) { cin >> h[i]; }
cst[0] = 0;
cst[1] = abs(h[1] - h[0]);
repr(i, 2, n - 1) {
cst[i] = min(abs(h[i] - h[i - 1]) + cst[i - 1],
abs(h[i] - h[i - 2]) + cst[i - 2]);
}
cout << cst[n - 1];
}
int main() {
fastio;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
// freopen("output.txt","w",stdout);
#endif
ll t = 1;
// cin>>t;
W(t) { solve(); }
return 0;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define fi first
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define fit(x) for (auto it = x.begin(); it != x.end(); ++it)
#define se second
#define mp make_pair
#define ALL(x) x.begin(), x.end()
#define ALP "abcdefghijklmnopqrstuvwxyz"
#define nline cout << "\n"
#define rep(i, x) for (i = 0; i < x; ++i)
#define repr(i, a, b) for (i = a; i <= b; ++i)
#define PLL pair<ll, ll>
#define VLL vector<ll>
#define W(t) while (t--)
#define modsum(a, b, M) (a % M + b % M) % M
#define modsub(a, b, M) (a % M - b % M + M) % M
#define modmul(a, b, M) (a % M * b % M) % M
#define moddiv(a, b, M) (a % M * modinv(b, M) % M) % M
#define seperate cout << "*****************\n";
const long long mi2 = 500000004;
const long long mi3 = 333333336;
const long long MOD = 1000000007;
#define ordered_set \
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_pset \
tree<PLL, null_type, less<PLL>, rb_tree_tag, \
tree_order_statistics_node_update>
int xcod[4] = {-1, 0, 1, 0};
int ycod[4] = {0, 1, 0, -1};
#define dbg(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
struct HASH {
size_t operator()(const pair<ll, ll> &x) const {
return hash<long long>()(((long long)x.first) ^
(((long long)x.second) << 32));
}
};
// unordered_map<pair<int,int>,int,HASH>mp;
// unordered_map<ll, ll, custom_hash> safe_map;
ll powermod(ll x, ll n, ll M) {
ll result = 1;
while (n > 0) {
if (n % 2 == 1)
result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result;
}
vector<ll> readll() {
cin >> ws;
vector<ll> v;
string input;
getline(cin, input);
cout << input;
istringstream is(input);
ll num;
while (is >> num)
v.pb(num);
return v;
}
/*
int BLOCK_SIZE;
inline bool mo_cmp(const pair< pair<int, int>, int> &x,const pair< pair<int,
int>, int> &y)
{
if ( (x.fi.fi/BLOCK_SIZE) != (y.fi.fi/BLOCK_SIZE) )
return x < y ;
return ((x.fi.fi/BLOCK_SIZE)&1)^(x.fi.se<y.fi.se) ;
}
*/
ll modinv(ll n, ll p) { return powermod(n, p - 2, p); }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll fact[1000005], invf[1000005];
void facmod(ll n, ll M) {
ll i;
fact[0] = fact[1] = 1;
for (i = 2; i <= n; ++i) {
fact[i] = ((fact[i - 1]) % M * (i % M)) % M;
}
invf[n] = modinv(fact[n], M);
for (i = n - 1; i >= 0; --i) {
invf[i] = invf[i + 1] * (i + 1);
invf[i] %= M;
}
}
/*
ll T=0;
ll p[200005], d[200005];
ll tin[200005], tout[200005];
vector<ll> g[200005];
bool vis[200005];
void dfs(ll v,ll par=1,ll dep=0) {
//dbg(v);
tin[v] = T++;
vis[v]=true;
p[v] = par;
d[v] = dep;
for (auto to : g[v]) {
if (vis[to]) continue;
dfs(to,v,dep+1);
}
tout[v] = T++;
}
*/
// ll treeSet() {
// ordered_set o_set;
// o_set.insert(1); //for duplicate elements use pair and use second element
// unique
// // find by order returns iterator of ith largest element;
// cout<<*(o_set.find_by_order(1)) //second smallest element;
// // Finding the number of elements
// // strictly less than k=4
// cout << o_set.order_of_key(4) ;
// // Deleting 2 from the set if it exists
// if (o_set.find(2) != o_set.end())
// o_set.erase(o_set.find(2));
// }
void solve() {
ll i, n;
cin >> n;
ll h[n + 4], cst[n + 4];
rep(i, n) { cin >> h[i]; }
cst[0] = 0;
cst[1] = abs(h[1] - h[0]);
repr(i, 2, n - 1) {
cst[i] = min(abs(h[i] - h[i - 1]) + cst[i - 1],
abs(h[i] - h[i - 2]) + cst[i - 2]);
}
cout << cst[n - 1];
}
int main() {
fastio;
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// //freopen("output.txt","w",stdout);
// #endif
ll t = 1;
// cin>>t;
W(t) { solve(); }
return 0;
}
|
replace
| 168 | 172 | 168 | 172 |
-11
| |
p03160
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
long long n, arr[100005], dp[100005];
long long f(long long a) {
if (a > n)
return 1e18;
if (a == n)
return 0;
if (dp[a] != -1)
return dp[a];
return min(abs(arr[a + 1] - arr[a]) + f(a + 1),
abs(arr[a + 2] - arr[a] + f(a + 2)));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
memset(dp, -1, sizeof(dp));
cin >> n;
for (long long i = 1; i <= n; i++) {
cin >> arr[i];
}
cout << f(1) << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, arr[100005], dp[100005];
long long f(long long a) {
if (a > n)
return 1e18;
if (a == n)
return 0;
if (dp[a] != -1)
return dp[a];
return dp[a] = min(abs(arr[a + 1] - arr[a]) + f(a + 1),
abs(arr[a + 2] - arr[a]) + f(a + 2));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
memset(dp, -1, sizeof(dp));
cin >> n;
for (long long i = 1; i <= n; i++) {
cin >> arr[i];
}
cout << f(1) << endl;
}
|
replace
| 10 | 12 | 10 | 12 |
TLE
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int h[10010];
int a[100100];
int dp[100100];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> h[i];
a[0] = 0;
for (int i = 1; i < n; i++)
a[i] = h[i] - h[i - 1];
dp[1] = abs(a[1]);
for (int i = 0; i + 2 < n; i++)
dp[i + 2] =
min(dp[i] + abs(a[i + 1] + a[i + 2]), dp[i + 1] + abs(a[i + 2]));
cout << dp[n - 1];
}
|
#include <bits/stdc++.h>
using namespace std;
int h[100100];
int a[100100];
int dp[100100];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> h[i];
a[0] = 0;
for (int i = 1; i < n; i++)
a[i] = h[i] - h[i - 1];
dp[1] = abs(a[1]);
for (int i = 0; i + 2 < n; i++)
dp[i + 2] =
min(dp[i] + abs(a[i + 1] + a[i + 2]), dp[i + 1] + abs(a[i + 2]));
cout << dp[n - 1];
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define max1 1000005
#define siz 100000
#define mod 998244353
#define inf 1e18 + 5
#define ll long long int
#define debug(x) cout << #x << " " << x << endl
#define jam(x) cout << "Case #" << x << ": "
typedef pair<ll, ll> pr;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll n;
cin >> n;
vector<ll> a(n);
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
vector<ll> dp(n, 0);
for (ll i = 1; i < n; i++) {
if (i == 1) {
dp[i] = abs(a[i] - a[i - 1]);
} else {
dp[i] = min(dp[i - 2] + abs(a[i] - a[i - 2]),
dp[i - 1] + abs(a[i] - a[i - 1]));
}
}
cout << dp[n - 1] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define max1 1000005
#define siz 100000
#define mod 998244353
#define inf 1e18 + 5
#define ll long long int
#define debug(x) cout << #x << " " << x << endl
#define jam(x) cout << "Case #" << x << ": "
typedef pair<ll, ll> pr;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
/*#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif*/
ll n;
cin >> n;
vector<ll> a(n);
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
vector<ll> dp(n, 0);
for (ll i = 1; i < n; i++) {
if (i == 1) {
dp[i] = abs(a[i] - a[i - 1]);
} else {
dp[i] = min(dp[i - 2] + abs(a[i] - a[i - 2]),
dp[i - 1] + abs(a[i] - a[i - 1]));
}
}
cout << dp[n - 1] << endl;
}
|
replace
| 14 | 18 | 14 | 18 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
// 💖 Hi, thanks for using ICIE! 💖
// 🔧 To use a custom code template, press Ctrl+Shift+P and select "ICIE Template
// configure" from the list 🔧 📝 If you spot any bugs or miss any features,
// create an issue at https://github.com/pustaczek/icie/issues 📝
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
int h[10005], dp[10005];
cin >> N;
for (int i = 0; i < N; i++) {
cin >> h[i];
}
dp[1] = abs(h[1] - h[0]);
for (int i = 2; i < N; i++) {
int c1 = dp[i - 1] + abs(h[i] - h[i - 1]);
int c2 = dp[i - 2] + abs(h[i] - h[i - 2]);
dp[i] = min(c1, c2);
}
cout << dp[N - 1];
}
|
#include <bits/stdc++.h>
using namespace std;
// 💖 Hi, thanks for using ICIE! 💖
// 🔧 To use a custom code template, press Ctrl+Shift+P and select "ICIE Template
// configure" from the list 🔧 📝 If you spot any bugs or miss any features,
// create an issue at https://github.com/pustaczek/icie/issues 📝
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
int h[100005], dp[100005];
cin >> N;
for (int i = 0; i < N; i++) {
cin >> h[i];
}
dp[1] = abs(h[1] - h[0]);
for (int i = 2; i < N; i++) {
int c1 = dp[i - 1] + abs(h[i] - h[i - 1]);
int c2 = dp[i - 2] + abs(h[i] - h[i - 2]);
dp[i] = min(c1, c2);
}
cout << dp[N - 1];
}
|
replace
| 12 | 13 | 12 | 13 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int dp[101000];
int main() {
int n;
scanf("%d", &n);
vector<int> a(1 << n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
memset(dp, 0, sizeof dp);
dp[0] = 0;
for (int i = 1; i < n; ++i) {
int op1 = INT_MAX, op2 = INT_MAX;
if (i >= 1) {
op1 = abs(a[i] - a[i - 1]) + dp[i - 1];
}
if (i >= 2) {
op2 = abs(a[i] - a[i - 2]) + dp[i - 2];
}
dp[i] = min(op1, op2);
}
printf("%d\n", dp[n - 1]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int dp[101000];
int main() {
int n;
scanf("%d", &n);
vector<int> a(n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
memset(dp, 0, sizeof dp);
dp[0] = 0;
for (int i = 1; i < n; ++i) {
int op1 = INT_MAX, op2 = INT_MAX;
if (i >= 1) {
op1 = abs(a[i] - a[i - 1]) + dp[i - 1];
}
if (i >= 2) {
op2 = abs(a[i] - a[i - 2]) + dp[i - 2];
}
dp[i] = min(op1, op2);
}
printf("%d\n", dp[n - 1]);
return 0;
}
|
replace
| 9 | 10 | 9 | 10 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
// #include <map>
#include <cmath>
#include <cstring>
#include <iomanip>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int uii;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
typedef vector<int> vii;
const int maxn = 1e5 + 5;
LL a[maxn], d[maxn];
int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
int n;
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
d[1] = abs(a[1] - a[0]);
for (int i = 2; i < n; ++i) {
d[i] =
min(d[i - 1] + abs(a[i - 1] - a[i]), d[i - 2] + abs(a[i - 2] - a[i]));
}
cout << d[n - 1] << endl;
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
// #include <map>
#include <cmath>
#include <cstring>
#include <iomanip>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int uii;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
typedef vector<int> vii;
const int maxn = 1e5 + 5;
LL a[maxn], d[maxn];
int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
int n;
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
d[1] = abs(a[1] - a[0]);
for (int i = 2; i < n; ++i) {
d[i] =
min(d[i - 1] + abs(a[i - 1] - a[i]), d[i - 2] + abs(a[i - 2] - a[i]));
}
cout << d[n - 1] << endl;
return 0;
}
|
replace
| 22 | 23 | 22 | 23 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define p(V) \
for (int iiv = 0; iiv < V.size(); iiv++) \
cout << V[iiv] << " ";
#define mp make_pair
#define pb push_back
#define graph vector<vector<int>>
#define pf first
#define ps second
#define pq priority_queue
const int N = 2e5;
const int l = 18;
const double pi = acos(-1);
int n, dp[N];
vector<int> v;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin >> n;
v.resize(n);
for (int i = 0; i < n; i++)
cin >> v[i];
dp[n - 2] = abs(v[n - 1] - v[n - 2]);
int def;
for (int i = n - 3; i >= 0; i--)
dp[i] =
min(dp[i + 1] + abs(v[i] - v[i + 1]), dp[i + 2] + abs(v[i] - v[i + 2]));
cout << dp[0];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define p(V) \
for (int iiv = 0; iiv < V.size(); iiv++) \
cout << V[iiv] << " ";
#define mp make_pair
#define pb push_back
#define graph vector<vector<int>>
#define pf first
#define ps second
#define pq priority_queue
const int N = 2e5;
const int l = 18;
const double pi = acos(-1);
int n, dp[N];
vector<int> v;
int main() {
cin >> n;
v.resize(n);
for (int i = 0; i < n; i++)
cin >> v[i];
dp[n - 2] = abs(v[n - 1] - v[n - 2]);
int def;
for (int i = n - 3; i >= 0; i--)
dp[i] =
min(dp[i + 1] + abs(v[i] - v[i + 1]), dp[i + 2] + abs(v[i] - v[i + 2]));
cout << dp[0];
return 0;
}
|
delete
| 21 | 25 | 21 | 21 |
-11
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define endl '\n'
#define ll long long
#define int long long
const int32_t INFint = 1e9;
const ll INFll = 1e18;
#define MOD 1000000007ll
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define foreach(it, v) \
for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define deb1(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define deb3(x, y, z) \
cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define deb4(a, b, c, d) \
cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define deb5(a, b, c, d, e) \
cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define deb6(a, b, c, d, e, f) \
cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
#define For(i, a, b) for (ll i = a; i < b; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define gll(a, n) \
for (ll i = 0; i < n; i++) \
cin >> a[i];
#define gint(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define setZero(a, n) \
for (int i = 0; i < n; i++) \
a[i] = 0;
#define printArray(a, s, e) \
for (int i = s; i < e; i++) { \
cout << a[i] << " "; \
} \
cout << endl;
//---------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------
int32_t main() {
fast;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
// cin >> t;
t = 1;
while (t--) {
int n;
cin >> n;
int arr[n];
gint(arr, n);
int dp[n];
dp[0] = 0;
dp[1] = abs(arr[1] - arr[0]);
for (int i = 2; i < n; i++) {
dp[i] = min((abs(arr[i] - arr[i - 1]) + dp[i - 1]),
(abs(arr[i] - arr[i - 2]) + dp[i - 2]));
}
cout << dp[n - 1];
}
}
|
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define endl '\n'
#define ll long long
#define int long long
const int32_t INFint = 1e9;
const ll INFll = 1e18;
#define MOD 1000000007ll
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define foreach(it, v) \
for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define deb1(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define deb3(x, y, z) \
cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define deb4(a, b, c, d) \
cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define deb5(a, b, c, d, e) \
cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define deb6(a, b, c, d, e, f) \
cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
#define For(i, a, b) for (ll i = a; i < b; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define gll(a, n) \
for (ll i = 0; i < n; i++) \
cin >> a[i];
#define gint(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define setZero(a, n) \
for (int i = 0; i < n; i++) \
a[i] = 0;
#define printArray(a, s, e) \
for (int i = s; i < e; i++) { \
cout << a[i] << " "; \
} \
cout << endl;
//---------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------------------
int32_t main() {
fast;
int t;
// cin >> t;
t = 1;
while (t--) {
int n;
cin >> n;
int arr[n];
gint(arr, n);
int dp[n];
dp[0] = 0;
dp[1] = abs(arr[1] - arr[0]);
for (int i = 2; i < n; i++) {
dp[i] = min((abs(arr[i] - arr[i - 1]) + dp[i - 1]),
(abs(arr[i] - arr[i - 2]) + dp[i - 2]));
}
cout << dp[n - 1];
}
}
|
delete
| 63 | 67 | 63 | 63 |
-11
| |
p03160
|
C++
|
Runtime Error
|
//***********************
// Author:kibi11
// Quarantine Days
//***********************
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define fr(i, n) for (int i = 0; i < n; i++)
#define fr1(i, a, b) for (int i = a; i < b; i++)
#define frr(i, a, k) for (int i = a; i >= k; i--)
#define same \
int t; \
cin >> t; \
while (t--)
#define check(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define f first
#define s second
#define XOX
//////////////////////////////////////////////////////////////////////////
/////////////////DEBUGING ZONE//////////////////////////////
vector<string> vec_splitter(string s) {
s += ',';
vector<string> res;
while (!s.empty()) {
res.push_back(s.substr(0, s.find(',')));
s = s.substr(s.find(',') + 1);
}
return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
__attribute__((unused)) int idx,
__attribute__((unused)) int LINE_NUM) {
cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
if (idx > 0)
cerr << ", ";
else
cerr << "Line(" << LINE_NUM << ") ";
stringstream ss;
ss << H;
cerr << args[idx] << " = " << ss.str();
debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) \
debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
///////////////////////////////////////////////////////////////////////////
ll powermod(ll base, ll exp, ll mod) {
ll result = 1;
while (exp != 0) {
if ((exp % 2) == 1) {
result = (result * base) % mod;
}
base = (base * base) % mod;
exp /= 2;
}
return result;
}
///////////////////////////////////////////////////////////////////////////
// Fuctions if any:
///////////////////////////////////////////////////////////////////////////
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt = clock();
// ios_base& scientific (ios_base& str);
#ifndef ONLINE_JUDGE
freopen("C:\\Users\\arpan\\Documents\\prog c++\\IN.txt", "r", stdin);
freopen("C:\\Users\\arpan\\Documents\\prog c++\\OUT.txt", "w", stdout);
freopen("C:\\Users\\arpan\\Documents\\prog c++\\Error.txt", "w", stderr);
#endif
int n;
cin >> n;
int a[n];
int dp[n];
memset(dp, 0, sizeof(dp));
fr(i, n) cin >> a[i];
fr1(i, 1, n) {
dp[i] = INT_MAX;
// check(dp[i]);
fr(j, 2) {
// debug(j);
if ((i - j - 1) >= 0) {
dp[i] = min({dp[i - j - 1] + abs(a[i] - a[i - j - 1]), dp[i]});
// check(dp[i]);
}
}
}
// fr(i,n)
// cout<<dp[i]<<" ";
cout << dp[n - 1] << endl;
cerr << "TIME = " << (double)1.0 * (clock() - tt) / CLOCKS_PER_SEC
<< " seconds" << endl;
return 0;
}
|
//***********************
// Author:kibi11
// Quarantine Days
//***********************
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define fr(i, n) for (int i = 0; i < n; i++)
#define fr1(i, a, b) for (int i = a; i < b; i++)
#define frr(i, a, k) for (int i = a; i >= k; i--)
#define same \
int t; \
cin >> t; \
while (t--)
#define check(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define f first
#define s second
#define XOX
//////////////////////////////////////////////////////////////////////////
/////////////////DEBUGING ZONE//////////////////////////////
vector<string> vec_splitter(string s) {
s += ',';
vector<string> res;
while (!s.empty()) {
res.push_back(s.substr(0, s.find(',')));
s = s.substr(s.find(',') + 1);
}
return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
__attribute__((unused)) int idx,
__attribute__((unused)) int LINE_NUM) {
cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
if (idx > 0)
cerr << ", ";
else
cerr << "Line(" << LINE_NUM << ") ";
stringstream ss;
ss << H;
cerr << args[idx] << " = " << ss.str();
debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) \
debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
///////////////////////////////////////////////////////////////////////////
ll powermod(ll base, ll exp, ll mod) {
ll result = 1;
while (exp != 0) {
if ((exp % 2) == 1) {
result = (result * base) % mod;
}
base = (base * base) % mod;
exp /= 2;
}
return result;
}
///////////////////////////////////////////////////////////////////////////
// Fuctions if any:
///////////////////////////////////////////////////////////////////////////
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt = clock();
// ios_base& scientific (ios_base& str);
// #ifndef ONLINE_JUDGE
// freopen("C:\\Users\\arpan\\Documents\\prog c++\\IN.txt","r",stdin);
// freopen("C:\\Users\\arpan\\Documents\\prog c++\\OUT.txt","w",stdout);
// freopen("C:\\Users\\arpan\\Documents\\prog c++\\Error.txt","w",stderr);
// #endif
int n;
cin >> n;
int a[n];
int dp[n];
memset(dp, 0, sizeof(dp));
fr(i, n) cin >> a[i];
fr1(i, 1, n) {
dp[i] = INT_MAX;
// check(dp[i]);
fr(j, 2) {
// debug(j);
if ((i - j - 1) >= 0) {
dp[i] = min({dp[i - j - 1] + abs(a[i] - a[i - j - 1]), dp[i]});
// check(dp[i]);
}
}
}
// fr(i,n)
// cout<<dp[i]<<" ";
cout << dp[n - 1] << endl;
cerr << "TIME = " << (double)1.0 * (clock() - tt) / CLOCKS_PER_SEC
<< " seconds" << endl;
return 0;
}
|
replace
| 84 | 89 | 84 | 89 |
-11
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
signed main() {
#ifndef ONLINE_JUDGE
freopen("solve.in", "r", stdin);
freopen("solve.out", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
int h[N], dp[N];
for (int i = 1; i <= n; i++)
cin >> h[i];
dp[1] = 0;
dp[2] = abs(h[2] - h[1]);
for (int i = 3; i <= n; i++) {
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
}
cout << dp[n] << "\n";
return false;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
int h[N], dp[N];
for (int i = 1; i <= n; i++)
cin >> h[i];
dp[1] = 0;
dp[2] = abs(h[2] - h[1]);
for (int i = 3; i <= n; i++) {
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
}
cout << dp[n] << "\n";
return false;
}
|
delete
| 8 | 12 | 8 | 8 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<lli, lli> pll;
typedef std::vector<lli> vll;
typedef std::vector<pll> vpll;
typedef std::vector<bool> vbb;
typedef map<lli, lli> mll;
typedef set<lli> sll;
typedef multiset<lli> msll;
lli MOD = 1e9 + 7;
lli INF = 1e18;
#define forr(i, p, n) for (i = p; i < n; i++)
#define be(a) a.begin(), a.end()
#define mp make_pair
#define um unordered_map
#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
lli bitc(lli n, lli x) { return ((n >> x) & 1); }
lli __gcd(lli a, lli b) { return b == 0 ? a : __gcd(b, a % b); }
lli sub(lli a, lli b, lli p = MOD) { return ((a % p) - (b % p) + p) % p; }
lli mult(lli a, lli b, lli p = MOD) { return ((a % p) * (b % p)) % p; }
lli add(lli a, lli b, lli p = MOD) { return (a % p + b % p) % p; }
// lli add(lli a,lli b,lli p=MOD){//if(a+b>=p){//return (a+b)-p;// }//return
// a+b;// }
lli fpow(lli n, lli k, lli p = MOD) {
lli r = 1;
while (k > 0) {
if (k & 1)
r = r * n % p;
n = n * n % p;
k = k >> 1;
}
return r;
}
lli inv(lli a, lli p = MOD) { return fpow(a, p - 2, p); }
lli fdiv(lli a, lli b, lli p = MOD) {
lli yinv = inv(b);
lli ans = (a * yinv) % p;
return ans;
}
template <typename T> istream &operator>>(istream &in, vector<T> &a) {
for (auto &item : a) {
in >> item;
}
return in;
}
template <typename T, typename U>
ostream &operator<<(ostream &out, pair<T, U> &a) {
cout << a.F << " " << a.S;
return out;
}
template <typename T, typename U>
istream &operator>>(istream &out, pair<T, U> &a) {
cin >> a.F >> a.S;
return out;
}
template <typename T, typename U>
ostream &operator<<(ostream &out, map<T, U> &a) {
for (auto &item : a) {
out << item << endl;
}
return out;
}
template <typename T> ostream &operator<<(ostream &out, vector<T> &a) {
for (auto &item : a) {
out << item << " ";
}
return out;
}
template <typename T> ostream &operator<<(ostream &out, vector<vector<T>> &a) {
for (auto &item : a) {
out << item << "\n";
}
return out;
}
#define print(a) \
for (auto p : a) \
cout << p << " "; \
cout << endl;
#define read(a) \
for (auto &p : a) \
cin >> p >> endl;
std::vector<bool> is_prime;
std::vector<lli> primes;
void sieve(lli n) {
is_prime.resize(n + 2, true);
primes.clear();
lli p;
for (p = 2; p * p <= n; p++) {
if (is_prime[p]) {
lli i;
for (i = p * p; i <= n; i += p) {
is_prime[i] = false;
}
}
}
is_prime[0] = is_prime[1] = false;
lli i;
for (i = 2; i <= n; i++) {
if (is_prime[i]) {
primes.eb(i);
}
}
}
mll prime_factors(lli n) {
mll s;
lli i;
lli tc = 0;
while (n % 2 == 0) {
tc++;
n /= 2;
}
if (tc > 0) {
s[2] = tc;
}
for (i = 3; i <= sqrt(n); i += 2) {
tc = 0;
while (n % i == 0) {
tc++;
n /= i;
}
if (tc > 0) {
s[i] = tc;
}
}
if (n > 2) {
s[n] += 1;
}
return s;
}
// FACTORIAL
std::vector<lli> fact_vec;
void fact_fun(lli n) {
fact_vec.resize(n + 10);
lli i;
fact_vec[0] = 1;
for (i = 1; i <= n + 2; i++) {
fact_vec[i] = (fact_vec[i - 1] * i) % MOD;
}
}
// declare
// class Sol{
// public:
// Sol(){
// }
// };
int main() {
lli i, j;
ios::sync_with_stdio(false);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
lli n;
cin >> n;
vll v(n);
cin >> v;
vll cost(n, INF);
cost[0] = 0;
forr(i, 1, n) {
if (i - 1 >= 0) {
cost[i] = min(cost[i], abs(v[i] - v[i - 1]) + cost[i - 1]);
}
if (i - 2 >= 0) {
cost[i] = min(cost[i], abs(v[i] - v[i - 2]) + cost[i - 2]);
}
}
cout << cost[n - 1] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<lli, lli> pll;
typedef std::vector<lli> vll;
typedef std::vector<pll> vpll;
typedef std::vector<bool> vbb;
typedef map<lli, lli> mll;
typedef set<lli> sll;
typedef multiset<lli> msll;
lli MOD = 1e9 + 7;
lli INF = 1e18;
#define forr(i, p, n) for (i = p; i < n; i++)
#define be(a) a.begin(), a.end()
#define mp make_pair
#define um unordered_map
#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
lli bitc(lli n, lli x) { return ((n >> x) & 1); }
lli __gcd(lli a, lli b) { return b == 0 ? a : __gcd(b, a % b); }
lli sub(lli a, lli b, lli p = MOD) { return ((a % p) - (b % p) + p) % p; }
lli mult(lli a, lli b, lli p = MOD) { return ((a % p) * (b % p)) % p; }
lli add(lli a, lli b, lli p = MOD) { return (a % p + b % p) % p; }
// lli add(lli a,lli b,lli p=MOD){//if(a+b>=p){//return (a+b)-p;// }//return
// a+b;// }
lli fpow(lli n, lli k, lli p = MOD) {
lli r = 1;
while (k > 0) {
if (k & 1)
r = r * n % p;
n = n * n % p;
k = k >> 1;
}
return r;
}
lli inv(lli a, lli p = MOD) { return fpow(a, p - 2, p); }
lli fdiv(lli a, lli b, lli p = MOD) {
lli yinv = inv(b);
lli ans = (a * yinv) % p;
return ans;
}
template <typename T> istream &operator>>(istream &in, vector<T> &a) {
for (auto &item : a) {
in >> item;
}
return in;
}
template <typename T, typename U>
ostream &operator<<(ostream &out, pair<T, U> &a) {
cout << a.F << " " << a.S;
return out;
}
template <typename T, typename U>
istream &operator>>(istream &out, pair<T, U> &a) {
cin >> a.F >> a.S;
return out;
}
template <typename T, typename U>
ostream &operator<<(ostream &out, map<T, U> &a) {
for (auto &item : a) {
out << item << endl;
}
return out;
}
template <typename T> ostream &operator<<(ostream &out, vector<T> &a) {
for (auto &item : a) {
out << item << " ";
}
return out;
}
template <typename T> ostream &operator<<(ostream &out, vector<vector<T>> &a) {
for (auto &item : a) {
out << item << "\n";
}
return out;
}
#define print(a) \
for (auto p : a) \
cout << p << " "; \
cout << endl;
#define read(a) \
for (auto &p : a) \
cin >> p >> endl;
std::vector<bool> is_prime;
std::vector<lli> primes;
void sieve(lli n) {
is_prime.resize(n + 2, true);
primes.clear();
lli p;
for (p = 2; p * p <= n; p++) {
if (is_prime[p]) {
lli i;
for (i = p * p; i <= n; i += p) {
is_prime[i] = false;
}
}
}
is_prime[0] = is_prime[1] = false;
lli i;
for (i = 2; i <= n; i++) {
if (is_prime[i]) {
primes.eb(i);
}
}
}
mll prime_factors(lli n) {
mll s;
lli i;
lli tc = 0;
while (n % 2 == 0) {
tc++;
n /= 2;
}
if (tc > 0) {
s[2] = tc;
}
for (i = 3; i <= sqrt(n); i += 2) {
tc = 0;
while (n % i == 0) {
tc++;
n /= i;
}
if (tc > 0) {
s[i] = tc;
}
}
if (n > 2) {
s[n] += 1;
}
return s;
}
// FACTORIAL
std::vector<lli> fact_vec;
void fact_fun(lli n) {
fact_vec.resize(n + 10);
lli i;
fact_vec[0] = 1;
for (i = 1; i <= n + 2; i++) {
fact_vec[i] = (fact_vec[i - 1] * i) % MOD;
}
}
// declare
// class Sol{
// public:
// Sol(){
// }
// };
int main() {
lli i, j;
ios::sync_with_stdio(false);
cin.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
lli n;
cin >> n;
vll v(n);
cin >> v;
vll cost(n, INF);
cost[0] = 0;
forr(i, 1, n) {
if (i - 1 >= 0) {
cost[i] = min(cost[i], abs(v[i] - v[i - 1]) + cost[i - 1]);
}
if (i - 2 >= 0) {
cost[i] = min(cost[i], abs(v[i] - v[i - 2]) + cost[i - 2]);
}
}
cout << cost[n - 1] << endl;
}
|
replace
| 169 | 173 | 169 | 173 |
-6
|
terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
|
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
vector<int> h(n);
vector<long long> dp(n, 1e18);
for (int i = 0; i < n; ++i) {
cin >> h[i];
}
dp[0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j <= i + 2 and j < n; ++j) {
dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[j]));
}
}
cout << dp[n - 1];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
vector<int> h(n);
vector<long long> dp(n, 1e18);
for (int i = 0; i < n; ++i) {
cin >> h[i];
}
dp[0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j <= i + 2 and j < n; ++j) {
dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
}
}
cout << dp[n - 1];
return 0;
}
|
replace
| 18 | 19 | 18 | 19 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> h(N), dp(1010);
for (int i = 0; i < N; i++)
cin >> h[i];
for (int i = 0; i < N; i++)
dp[i] = INT_MAX;
dp[0] = 0;
for (int i = 0; i < N; i++) {
if (dp[i + 1] > dp[i] + abs(h[i] - h[i + 1]))
dp[i + 1] = dp[i] + abs(h[i] - h[i + 1]);
if (dp[i + 2] > dp[i] + abs(h[i] - h[i + 2]))
dp[i + 2] = dp[i] + abs(h[i] - h[i + 2]);
}
cout << dp[N - 1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> h(N), dp(100010);
for (int i = 0; i < N; i++)
cin >> h[i];
for (int i = 0; i < N; i++)
dp[i] = INT_MAX;
dp[0] = 0;
for (int i = 0; i < N; i++) {
if (dp[i + 1] > dp[i] + abs(h[i] - h[i + 1]))
dp[i + 1] = dp[i] + abs(h[i] - h[i + 1]);
if (dp[i + 2] > dp[i] + abs(h[i] - h[i + 2]))
dp[i + 2] = dp[i] + abs(h[i] - h[i + 2]);
}
cout << dp[N - 1] << endl;
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#define lli long long int
using namespace std;
lli cache[100005];
lli getmin(vector<int> h, int i, int n) {
if (i == n - 1) {
return 0;
}
if (cache[i] != -1) {
return cache[i];
}
lli r1 = INT_MAX, r2 = INT_MAX;
if ((i + 1) <= (n - 1)) {
r1 = abs(h[i] - h[i + 1]) + getmin(h, i + 1, n);
}
if ((i + 2) <= (n - 1)) {
r2 = abs(h[i] - h[i + 2]) + getmin(h, i + 2, n);
}
cache[i] = min(r1, r2);
return cache[i];
}
void solve() {
int n;
cin >> n;
vector<int> h(n);
for (int i = 0; i < n; i++) {
cin >> h[i];
cache[i] = -1;
}
cache[n] = -1;
lli res = getmin(h, 0, n);
cout << res << endl;
}
int main() { solve(); }
|
#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#define lli long long int
using namespace std;
lli cache[100005];
lli getmin(vector<int> &h, int i, int n) {
if (i == n - 1) {
return 0;
}
if (cache[i] != -1) {
return cache[i];
}
lli r1 = INT_MAX, r2 = INT_MAX;
if ((i + 1) <= (n - 1)) {
r1 = abs(h[i] - h[i + 1]) + getmin(h, i + 1, n);
}
if ((i + 2) <= (n - 1)) {
r2 = abs(h[i] - h[i + 2]) + getmin(h, i + 2, n);
}
cache[i] = min(r1, r2);
return cache[i];
}
void solve() {
int n;
cin >> n;
vector<int> h(n);
for (int i = 0; i < n; i++) {
cin >> h[i];
cache[i] = -1;
}
cache[n] = -1;
lli res = getmin(h, 0, n);
cout << res << endl;
}
int main() { solve(); }
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define z 500000000000000000
#define sh 500000
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, i;
cin >> n;
int ar[n + 1];
for (i = 1; i <= n; i++)
cin >> ar[i];
int dp[n + 1];
dp[1] = 0;
dp[2] = abs(ar[2] - ar[1]);
for (i = 3; i <= n; i++) {
dp[i] = min(dp[i - 1] + abs(ar[i] - ar[i - 1]),
dp[i - 2] + abs(ar[i] - ar[i - 2]));
}
cout << dp[n];
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define z 500000000000000000
#define sh 500000
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, i;
cin >> n;
int ar[n + 1];
for (i = 1; i <= n; i++)
cin >> ar[i];
int dp[n + 1];
dp[1] = 0;
dp[2] = abs(ar[2] - ar[1]);
for (i = 3; i <= n; i++) {
dp[i] = min(dp[i - 1] + abs(ar[i] - ar[i - 1]),
dp[i - 2] + abs(ar[i] - ar[i - 2]));
}
cout << dp[n];
}
|
delete
| 9 | 13 | 9 | 9 |
-11
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define whole(v) begin(v), end(v)
#define print(c, n) \
for (int i = 0; i < n; i++) \
cout << c[i] << " ";
#define MOD 1000000007
#define INF 0x3f3f3f3f
int a[100005], dp[100005];
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
std::ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
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]));
for (int i = 3; i < n; i++) {
dp[i] =
min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
}
cout << dp[n - 1] << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define whole(v) begin(v), end(v)
#define print(c, n) \
for (int i = 0; i < n; i++) \
cout << c[i] << " ";
#define MOD 1000000007
#define INF 0x3f3f3f3f
int a[100005], dp[100005];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
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]));
for (int i = 3; i < n; i++) {
dp[i] =
min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
}
cout << dp[n - 1] << "\n";
return 0;
}
|
replace
| 14 | 18 | 14 | 15 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;
const double PI = 3.14159265358979323846;
#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))
#define rep(i, N) for (int i = 0; i < N; ++i)
#define CEIL(x, y) (((x) + (y)-1) / (y))
#define MOD 1000000007ULL
int dp[10000];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vs32 h(N);
rep(i, N) cin >> h[i];
dp[0] = 0;
dp[1] = abs(h[1] - h[0]);
for (int i = 2; i < N; ++i) {
dp[i] =
MIN(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
}
cout << dp[N - 1] << "\n";
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;
const double PI = 3.14159265358979323846;
#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))
#define rep(i, N) for (int i = 0; i < N; ++i)
#define CEIL(x, y) (((x) + (y)-1) / (y))
#define MOD 1000000007ULL
int dp[100000];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vs32 h(N);
rep(i, N) cin >> h[i];
dp[0] = 0;
dp[1] = abs(h[1] - h[0]);
for (int i = 2; i < N; ++i) {
dp[i] =
MIN(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
}
cout << dp[N - 1] << "\n";
return 0;
}
|
replace
| 36 | 37 | 36 | 37 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
#define ll long long
#define fr first
#define se second
#define fi(i, s, e, inc) for (auto i = s; i < e; i += inc)
#define fie(i, s, e, inc) for (auto i = s; i <= e; i += inc)
#define fd(i, s, e, dec) for (auto i = s; i > e; i -= dec)
#define fde(i, s, e, dec) for (auto i = s; i >= e; i -= dec)
#define umap tr1::unordered_map
#define nl cout << "\n";
#define vt vector
#define pb push_back
#define pr(x) cout << x;
#define ps(x) cout << x << " ";
#define sp cout << " ";
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rev reverse
#define tc \
ll t; \
cin >> t; \
while (t--)
#define pq priority_queue
ll a[100005];
ll n;
ll dp[100005];
ll solve(ll idx) {
if (idx == n - 1)
return 0;
if (idx >= n)
return INT_MAX;
if (dp[idx] != -1)
return dp[idx];
// jump one step
ll jump_one = abs(a[idx] - a[idx + 1]) + solve(idx + 1);
// jump two step
ll jump_two = INT_MAX;
if (idx + 2 < n)
jump_two = abs(a[idx] - a[idx + 2]) + solve(idx + 2);
return dp[idx] = min(jump_one, jump_two);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
fi(i, 0, n, 1) cin >> a[i];
memset(dp, -1, sizeof(dp));
pr(solve(0)) nl return 0;
}
|
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
#define ll long long
#define fr first
#define se second
#define fi(i, s, e, inc) for (auto i = s; i < e; i += inc)
#define fie(i, s, e, inc) for (auto i = s; i <= e; i += inc)
#define fd(i, s, e, dec) for (auto i = s; i > e; i -= dec)
#define fde(i, s, e, dec) for (auto i = s; i >= e; i -= dec)
#define umap tr1::unordered_map
#define nl cout << "\n";
#define vt vector
#define pb push_back
#define pr(x) cout << x;
#define ps(x) cout << x << " ";
#define sp cout << " ";
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rev reverse
#define tc \
ll t; \
cin >> t; \
while (t--)
#define pq priority_queue
ll a[100005];
ll n;
ll dp[100005];
ll solve(ll idx) {
if (idx == n - 1)
return 0;
if (idx >= n)
return INT_MAX;
if (dp[idx] != -1)
return dp[idx];
// jump one step
ll jump_one = abs(a[idx] - a[idx + 1]) + solve(idx + 1);
// jump two step
ll jump_two = INT_MAX;
if (idx + 2 < n)
jump_two = abs(a[idx] - a[idx + 2]) + solve(idx + 2);
return dp[idx] = min(jump_one, jump_two);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
fi(i, 0, n, 1) cin >> a[i];
memset(dp, -1, sizeof(dp));
pr(solve(0)) nl return 0;
}
|
delete
| 49 | 53 | 49 | 49 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
using namespace std;
typedef long long ll;
int n;
ll h[100005];
ll memo[100005];
ll dp(int i) {
if (i == n - 1)
return 0;
if (i >= n)
return 10000000000;
if (memo[i] != -1) {
return memo[i];
}
return memo[i] = min(abs(h[i] - h[i + 1]) + dp(i + 1),
abs(h[i] - h[i + 2]) + dp(i + 2));
}
int main() {
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
memset(memo, -1, sizeof(memo));
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> h[i];
}
cout << dp(0) << "\n";
return 0;
}
|
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
using namespace std;
typedef long long ll;
int n;
ll h[100005];
ll memo[100005];
ll dp(int i) {
if (i == n - 1)
return 0;
if (i >= n)
return 10000000000;
if (memo[i] != -1) {
return memo[i];
}
return memo[i] = min(abs(h[i] - h[i + 1]) + dp(i + 1),
abs(h[i] - h[i + 2]) + dp(i + 2));
}
int main() {
memset(memo, -1, sizeof(memo));
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> h[i];
}
cout << dp(0) << "\n";
return 0;
}
|
delete
| 28 | 35 | 28 | 28 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int h[11000] = {}, dp[11000] = {};
for (int i = 0; i < n; i++) {
cin >> h[i];
}
dp[0] = 0;
dp[1] = abs(h[1] - h[0]);
for (int i = 2; i < n; i++) {
dp[i] = (abs(h[i] - h[i - 1]) + dp[i - 1] < abs(h[i] - h[i - 2]) + dp[i - 2]
? abs(h[i] - h[i - 1]) + dp[i - 1]
: abs(h[i] - h[i - 2]) + dp[i - 2]);
}
cout << dp[n - 1] << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int h[110000] = {}, dp[110000] = {};
for (int i = 0; i < n; i++) {
cin >> h[i];
}
dp[0] = 0;
dp[1] = abs(h[1] - h[0]);
for (int i = 2; i < n; i++) {
dp[i] = (abs(h[i] - h[i - 1]) + dp[i - 1] < abs(h[i] - h[i - 2]) + dp[i - 2]
? abs(h[i] - h[i - 1]) + dp[i - 1]
: abs(h[i] - h[i - 2]) + dp[i - 2]);
}
cout << dp[n - 1] << endl;
return 0;
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define show(x) cout << #x << " " << x << " ";
#define f(i, j, k) for (int i = j; i <= k; i++)
#define fr(i, j, k) for (int i = j; i >= k; i--)
#define ll long long
#define all(A) A.begin(), A.end()
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
const int MSIZE = 1e2 + 5;
const int MOD = 1e9 + 7;
int arr[MSIZE];
int dp[MSIZE];
int main() {
FIO int n;
cin >> n;
f(i, 0, n - 1) cin >> arr[i];
dp[0] = 0;
dp[1] = abs(arr[0] - arr[1]);
f(i, 2, n - 1) {
dp[i] = min(dp[i - 1] + abs(arr[i] - arr[i - 1]),
dp[i - 2] + abs(arr[i] - arr[i - 2]));
}
cout << dp[n - 1] << endl;
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define show(x) cout << #x << " " << x << " ";
#define f(i, j, k) for (int i = j; i <= k; i++)
#define fr(i, j, k) for (int i = j; i >= k; i--)
#define ll long long
#define all(A) A.begin(), A.end()
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
const int MSIZE = 2e5 + 5;
const int MOD = 1e9 + 7;
int arr[MSIZE];
int dp[MSIZE];
int main() {
FIO int n;
cin >> n;
f(i, 0, n - 1) cin >> arr[i];
dp[0] = 0;
dp[1] = abs(arr[0] - arr[1]);
f(i, 2, n - 1) {
dp[i] = min(dp[i - 1] + abs(arr[i] - arr[i - 1]),
dp[i - 2] + abs(arr[i] - arr[i - 2]));
}
cout << dp[n - 1] << endl;
return 0;
}
|
replace
| 12 | 13 | 12 | 13 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define END cout << endl;
#else
#define DEB(X) \
{}
#define END \
{}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int, int> P;
struct edge {
int to, cost;
};
const int INF = 100000000000000000;
const int INF2 = 9223372036854775807;
const int MOD = 1000000007;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define min(X, Y) (((int)(X) < (int)(Y)) ? (X) : (Y))
#define max(X, Y) (((int)(X) > (int)(Y)) ? (X) : (Y))
#define MAX(X, Y) (*max_element(X, Y))
#define MIN(X, Y) (*min_element(X, Y))
#define NP(X, Y) next_permutation(X, Y)
#define setp(X, Y) cout << fixed << setprecision(Y) << X;
int ceil2(int a, int b) {
if (a % b == 0) {
return a / b;
} else {
return a / b + 1;
}
}
int pow2(int a, int b) {
int r = 1;
for (int i = 1; i <= b; i++) {
r *= a;
}
return r;
}
int Log2(int a) {
int t = 0;
while (1) {
if (a == 0 || a == 1) {
break;
}
a /= 2;
t++;
}
return t;
}
int N;
int H[1010];
int dp[100010];
signed main() {
cin >> N;
REP(i, N) {
cin >> H[i];
dp[i] = INF;
}
dp[0] = 0;
for (int i = 0; i < N; i++) {
dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i] - H[i + 2]));
dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i] - H[i + 1]));
}
cout << dp[N - 1] << endl;
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
// #define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define END cout << endl;
#else
#define DEB(X) \
{}
#define END \
{}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int, int> P;
struct edge {
int to, cost;
};
const int INF = 100000000000000000;
const int INF2 = 9223372036854775807;
const int MOD = 1000000007;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define min(X, Y) (((int)(X) < (int)(Y)) ? (X) : (Y))
#define max(X, Y) (((int)(X) > (int)(Y)) ? (X) : (Y))
#define MAX(X, Y) (*max_element(X, Y))
#define MIN(X, Y) (*min_element(X, Y))
#define NP(X, Y) next_permutation(X, Y)
#define setp(X, Y) cout << fixed << setprecision(Y) << X;
int ceil2(int a, int b) {
if (a % b == 0) {
return a / b;
} else {
return a / b + 1;
}
}
int pow2(int a, int b) {
int r = 1;
for (int i = 1; i <= b; i++) {
r *= a;
}
return r;
}
int Log2(int a) {
int t = 0;
while (1) {
if (a == 0 || a == 1) {
break;
}
a /= 2;
t++;
}
return t;
}
int N;
int H[100010];
int dp[100010];
signed main() {
cin >> N;
REP(i, N) {
cin >> H[i];
dp[i] = INF;
}
dp[0] = 0;
for (int i = 0; i < N; i++) {
dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i] - H[i + 2]));
dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i] - H[i + 1]));
}
cout << dp[N - 1] << endl;
return 0;
}
|
replace
| 74 | 75 | 74 | 75 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()
const long long INF = 1LL << 60;
const int mod = 1000000007;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int N;
vector<int> H(100010);
vector<int> H1(100010);
vector<int> H2(100010);
int MAX_N = 100000;
vector<ll> dp(10010, INF);
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cin >> N;
REP(i, N) { cin >> H.at(i); }
for (int i = 0; i < N - 1; i++) {
H1.at(i) = abs(H.at(i) - H.at(i + 1));
}
for (int i = 0; i < N - 2; i++) {
H2.at(i) = abs(H.at(i) - H.at(i + 2));
}
dp.at(0) = 0;
for (int i = 0; i < N; i++) {
chmin(dp.at(i + 1), dp.at(i) + H1.at(i));
chmin(dp.at(i + 2), dp.at(i) + H2.at(i));
}
cout << dp.at(N - 1) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()
const long long INF = 1LL << 60;
const int mod = 1000000007;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int N;
vector<int> H(100010);
vector<int> H1(100010);
vector<int> H2(100010);
int MAX_N = 100000;
vector<ll> dp(100010, INF);
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cin >> N;
REP(i, N) { cin >> H.at(i); }
for (int i = 0; i < N - 1; i++) {
H1.at(i) = abs(H.at(i) - H.at(i + 1));
}
for (int i = 0; i < N - 2; i++) {
H2.at(i) = abs(H.at(i) - H.at(i + 2));
}
dp.at(0) = 0;
for (int i = 0; i < N; i++) {
chmin(dp.at(i + 1), dp.at(i) + H1.at(i));
chmin(dp.at(i + 2), dp.at(i) + H2.at(i));
}
cout << dp.at(N - 1) << endl;
return 0;
}
|
replace
| 38 | 39 | 38 | 39 |
0
| |
p03160
|
C++
|
Time Limit Exceeded
|
/*author* Priyanshu Shrivastav (from IIT Palakkad) *
* *_ __ ___ _ ______ ___ _ ____ ___ ___| |_ *
* | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
* | | | | | | | | (_| (_) | | | \ V /| | (__| |_ *
* |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
When I wrote this, only God and I understood what I was doing
** * * * * * * * Now, only God knows * * * * * * */
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(nullptr)
#define PREC \
cout.precision(10); \
cout << fixed
using namespace std;
const int N = (int)1e5 + 4;
int n;
int memo[N], h[N];
int dp(int i) {
if (i >= n)
return 0;
else if (memo[i] != -1)
return memo[i];
else {
int j1 = dp(i + 1) + abs(h[i] - h[i + 1]),
j2 = (i + 2 <= n ? dp(i + 2) + abs(h[i] - h[i + 2]) : INT_MAX);
return min(j1, j2);
}
}
int main() {
IOS;
PREC;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> h[i], memo[i] = -1;
cout << dp(1) << endl;
return EXIT_SUCCESS;
}
|
/*author* Priyanshu Shrivastav (from IIT Palakkad) *
* *_ __ ___ _ ______ ___ _ ____ ___ ___| |_ *
* | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
* | | | | | | | | (_| (_) | | | \ V /| | (__| |_ *
* |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
When I wrote this, only God and I understood what I was doing
** * * * * * * * Now, only God knows * * * * * * */
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(nullptr)
#define PREC \
cout.precision(10); \
cout << fixed
using namespace std;
const int N = (int)1e5 + 4;
int n;
int memo[N], h[N];
int dp(int i) {
if (i >= n)
return 0;
else if (memo[i] != -1)
return memo[i];
else {
int j1 = dp(i + 1) + abs(h[i] - h[i + 1]),
j2 = (i + 2 <= n ? dp(i + 2) + abs(h[i] - h[i + 2]) : INT_MAX);
return memo[i] = min(j1, j2);
}
}
int main() {
IOS;
PREC;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> h[i], memo[i] = -1;
cout << dp(1) << endl;
return EXIT_SUCCESS;
}
|
replace
| 28 | 29 | 28 | 29 |
TLE
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define w(t) \
ll t; \
cin >> t; \
while (t--)
int main() {
// w(t)
//{
ll n, x, y, W, i, j, z = 0, k = 0, c = 0, s = 0;
cin >> n;
ll h[n];
ll dp[1005];
// map<ll,ll>mp;
for (i = 0; i < n; i++) {
cin >> h[i];
// cout<<h[i];
}
dp[0] = 0;
dp[1] = abs(h[0] - h[1]);
// cout<<dp[1];
for (i = 2; i < n; i++) {
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
}
cout << dp[n - 1];
}
//
// cout<<a[i]<<b[j];
/*if(flag==1)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;*/
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define w(t) \
ll t; \
cin >> t; \
while (t--)
int main() {
// w(t)
//{
ll n, x, y, W, i, j, z = 0, k = 0, c = 0, s = 0;
cin >> n;
ll h[n];
ll dp[100005];
// map<ll,ll>mp;
for (i = 0; i < n; i++) {
cin >> h[i];
// cout<<h[i];
}
dp[0] = 0;
dp[1] = abs(h[0] - h[1]);
// cout<<dp[1];
for (i = 2; i < n; i++) {
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
}
cout << dp[n - 1];
}
//
// cout<<a[i]<<b[j];
/*if(flag==1)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;*/
|
replace
| 16 | 17 | 16 | 17 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define int long long
#define w(t) \
int t; \
cin >> t; \
while (t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int, int>
#define vi vector<int>
#define umapi unordered_map<int, int>
const int m = 998244353;
using namespace std;
void FIO() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main() {
FIO();
int n;
cin >> n;
int array[n], dp[n];
for (int i = 0; i < n; i++) {
cin >> array[i];
}
for (int i = 0; i < n; i++)
dp[i] = 1e9;
dp[0] = 0;
for (int i = 0; i < n; i++) {
dp[i + 1] = min(dp[i + 1], dp[i] + abs(array[i] - array[i + 1]));
dp[i + 2] = min(dp[i + 2], dp[i] + abs(array[i] - array[i + 2]));
}
cout << dp[n - 1] << "\n";
return 0;
}
|
#include <bits/stdc++.h>
#define int long long
#define w(t) \
int t; \
cin >> t; \
while (t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int, int>
#define vi vector<int>
#define umapi unordered_map<int, int>
const int m = 998244353;
using namespace std;
void FIO() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main() {
// FIO();
int n;
cin >> n;
int array[n], dp[n];
for (int i = 0; i < n; i++) {
cin >> array[i];
}
for (int i = 0; i < n; i++)
dp[i] = 1e9;
dp[0] = 0;
for (int i = 0; i < n; i++) {
dp[i + 1] = min(dp[i + 1], dp[i] + abs(array[i] - array[i + 1]));
dp[i + 2] = min(dp[i + 2], dp[i] + abs(array[i] - array[i + 2]));
}
cout << dp[n - 1] << "\n";
return 0;
}
|
replace
| 30 | 31 | 30 | 31 |
-11
| |
p03160
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-ffloat-store")
#pragma GCC optimize("-fno-defer-pop")
#define all(a) a.begin(), a.end()
#define ll long long int
#define ld long double
ll power(ll a, ll b, ll m) {
if (b == 0)
return 1;
if (b == 1)
return a % m;
ll t = power(a, b / 2, m) % m;
t = (t * t) % m;
if (b & 1)
t = ((t % m) * (a % m)) % m;
return t;
}
ll modInverse(ll a, ll m) { return power(a, m - 2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
ll dp[100001];
ll maxval(ll ar[], ll n, ll i) {
if (i == 0) {
return 0;
}
if (i == 1) {
return abs(ar[0] - ar[1]);
}
ll a, b;
a = maxval(ar, n, i - 1) + abs(ar[i] - ar[i - 1]);
b = maxval(ar, n, i - 2) + abs(ar[i] - ar[i - 2]);
return dp[i] = min(a, b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
memset(dp, -1, sizeof(dp));
ll i, j, k, l, n;
cin >> n;
ll ar[n];
for (i = 0; i < n; i++) {
cin >> ar[i];
}
k = maxval(ar, n, n - 1);
cout << k;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-ffloat-store")
#pragma GCC optimize("-fno-defer-pop")
#define all(a) a.begin(), a.end()
#define ll long long int
#define ld long double
ll power(ll a, ll b, ll m) {
if (b == 0)
return 1;
if (b == 1)
return a % m;
ll t = power(a, b / 2, m) % m;
t = (t * t) % m;
if (b & 1)
t = ((t % m) * (a % m)) % m;
return t;
}
ll modInverse(ll a, ll m) { return power(a, m - 2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
ll dp[100001];
ll maxval(ll ar[], ll n, ll i) {
if (i == 0) {
return 0;
}
if (i == 1) {
return abs(ar[0] - ar[1]);
}
if (dp[i] != -1) {
return dp[i];
}
ll a, b;
a = maxval(ar, n, i - 1) + abs(ar[i] - ar[i - 1]);
b = maxval(ar, n, i - 2) + abs(ar[i] - ar[i - 2]);
return dp[i] = min(a, b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
memset(dp, -1, sizeof(dp));
ll i, j, k, l, n;
cin >> n;
ll ar[n];
for (i = 0; i < n; i++) {
cin >> ar[i];
}
k = maxval(ar, n, n - 1);
cout << k;
return 0;
}
|
insert
| 35 | 35 | 35 | 38 |
TLE
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ROCK \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define f first
#define sec second
using namespace std;
using namespace __gnu_pbds;
const long long int linf = (long long)9223372036854775807;
const int dx[8] = {0, 0, 1, -1, 1, -1, 1, -1},
dy[9] = {1, -1, 0, 0, 1, -1, -1, 1};
typedef long long int ll;
const int N = 1e5 + 3, sz = 1e4 + 5;
ll arr[sz], dp[N], n;
ll solve(int pos) {
if (pos == n - 1)
return 0;
if (dp[pos] != -1)
return dp[pos];
ll onestep = 1e9;
ll twostep = 1e9;
if (pos + 1 < n)
onestep = solve(pos + 1) + abs(arr[pos] - arr[pos + 1]);
if (pos + 2 < n)
twostep = solve(pos + 2) + abs(arr[pos] - arr[pos + 2]);
ll ans = min(onestep, twostep);
return dp[pos] = ans;
}
int main() {
ROCK;
memset(dp, -1, sizeof dp);
cin >> n;
for (int i = 0; i < n; i++)
cin >> arr[i];
cout << solve(0) << endl;
return 0;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ROCK \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define f first
#define sec second
using namespace std;
using namespace __gnu_pbds;
const long long int linf = (long long)9223372036854775807;
const int dx[8] = {0, 0, 1, -1, 1, -1, 1, -1},
dy[9] = {1, -1, 0, 0, 1, -1, -1, 1};
typedef long long int ll;
const int N = 1e5 + 3;
ll arr[N], dp[N], n;
ll solve(int pos) {
if (pos == n - 1)
return 0;
if (dp[pos] != -1)
return dp[pos];
ll onestep = 1e9;
ll twostep = 1e9;
if (pos + 1 < n)
onestep = solve(pos + 1) + abs(arr[pos] - arr[pos + 1]);
if (pos + 2 < n)
twostep = solve(pos + 2) + abs(arr[pos] - arr[pos + 2]);
ll ans = min(onestep, twostep);
return dp[pos] = ans;
}
int main() {
ROCK;
memset(dp, -1, sizeof dp);
cin >> n;
for (int i = 0; i < n; i++)
cin >> arr[i];
cout << solve(0) << endl;
return 0;
}
|
replace
| 16 | 18 | 16 | 18 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int *a;
int dp[40001];
int n;
int f(int x) {
if (x == n + 1)
return 0;
else {
dp[x] =
min(dp[x - 2] + abs(a[x - 2] - a[x]), dp[x - 1] + abs(a[x - 1] - a[x]));
return f(x + 1);
}
}
int main() {
cin >> n;
a = new int[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
dp[2] = abs(a[1] - a[2]);
f(3);
cout << dp[n];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int *a;
int dp[500001];
int n;
int f(int x) {
if (x == n + 1)
return 0;
else {
dp[x] =
min(dp[x - 2] + abs(a[x - 2] - a[x]), dp[x - 1] + abs(a[x - 1] - a[x]));
return f(x + 1);
}
}
int main() {
cin >> n;
a = new int[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
dp[2] = abs(a[1] - a[2]);
f(3);
cout << dp[n];
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
signed main() {
int n, h[10005], dp[10005] = {};
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
dp[1] = 0;
for (int i = 2; i <= n; i++) {
if (i != 2) {
dp[i] = min(abs(h[i] - h[i - 2]) + dp[i - 2],
abs(h[i] - h[i - 1]) + dp[i - 1]);
} else {
dp[i] = abs(h[i] - h[i - 1]) + dp[i - 1];
}
}
cout << dp[n] << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
signed main() {
int n, h[100005], dp[100005] = {};
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
dp[1] = 0;
for (int i = 2; i <= n; i++) {
if (i != 2) {
dp[i] = min(abs(h[i] - h[i - 2]) + dp[i - 2],
abs(h[i] - h[i - 1]) + dp[i - 1]);
} else {
dp[i] = abs(h[i] - h[i - 1]) + dp[i - 1];
}
}
cout << dp[n] << "\n";
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define f(i, x, n) for (ll i = x; i < n; i++)
#define fl(i, x, n) for (ll i = n; i >= x; i--)
#define mod (ll)1e9 + 7
#define print(x) cout << x << endl
#define vec vector<ll>
#define pai pair<ll, ll>
#define itr(it) ::iterator it
#define MAX (ll)1e16
#define MIN (ll) - 1e16
#define X first
#define Y second
#define up upper_bound
#define lo lower_bound
using namespace std;
/////////// /// /// /// /// //////////// /// ///
/// /// /// /// /// /// /// /// ///
/// /// /// /// /// /// /// /// ///
/////////// /////////// /// /// //////////// ////////////
/// /// /// /// /// /// /// /// ///
/// /// /// /// /// /// /// /// ///
/////////// /// /// //////////// //////////// /// ///
ll minn(ll a, ll b) {
if (a > b)
return b;
return a;
}
ll maxx2(ll a, ll b) {
if (a > b)
return a;
return b;
}
ll maxx(ll a, ll b, ll c) { return maxx2(a, maxx2(b, c)); }
ll gcdd(ll a, ll b) {
if (b == 0)
return a;
else
return gcdd(b, a % b);
}
ll dsum(ll n) {
ll sum = 0;
while (n > 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
ll poww(ll a, ll b) {
if (b <= 0)
return 1;
if (b == 1)
return a;
else
return poww(a, b / 2) * poww(a, b / 2) * poww(a, b % 2);
}
ll sumsq(ll x, ll y, ll z) {
return (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x);
}
ll n, a[200001], dp[200001] = {0};
ll solve(ll i) {
if (dp[i] != -1)
return dp[i];
if (i <= 0) {
return 0;
}
if (i == 1) {
dp[1] = abs(a[1] - a[0]);
return abs(a[1] - a[0]);
}
dp[i] = minn(abs(a[i] - a[i - 1]) + solve(i - 1),
abs(a[i] - a[i - 2]) + solve(i - 2));
return dp[i];
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
IOS;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin >> n;
f(i, 0, n) { cin >> a[i]; }
f(i, 0, n) { dp[i] = -1; }
ll ans = solve(n - 1);
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define f(i, x, n) for (ll i = x; i < n; i++)
#define fl(i, x, n) for (ll i = n; i >= x; i--)
#define mod (ll)1e9 + 7
#define print(x) cout << x << endl
#define vec vector<ll>
#define pai pair<ll, ll>
#define itr(it) ::iterator it
#define MAX (ll)1e16
#define MIN (ll) - 1e16
#define X first
#define Y second
#define up upper_bound
#define lo lower_bound
using namespace std;
/////////// /// /// /// /// //////////// /// ///
/// /// /// /// /// /// /// /// ///
/// /// /// /// /// /// /// /// ///
/////////// /////////// /// /// //////////// ////////////
/// /// /// /// /// /// /// /// ///
/// /// /// /// /// /// /// /// ///
/////////// /// /// //////////// //////////// /// ///
ll minn(ll a, ll b) {
if (a > b)
return b;
return a;
}
ll maxx2(ll a, ll b) {
if (a > b)
return a;
return b;
}
ll maxx(ll a, ll b, ll c) { return maxx2(a, maxx2(b, c)); }
ll gcdd(ll a, ll b) {
if (b == 0)
return a;
else
return gcdd(b, a % b);
}
ll dsum(ll n) {
ll sum = 0;
while (n > 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
ll poww(ll a, ll b) {
if (b <= 0)
return 1;
if (b == 1)
return a;
else
return poww(a, b / 2) * poww(a, b / 2) * poww(a, b % 2);
}
ll sumsq(ll x, ll y, ll z) {
return (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x);
}
ll n, a[200001], dp[200001] = {0};
ll solve(ll i) {
if (dp[i] != -1)
return dp[i];
if (i <= 0) {
return 0;
}
if (i == 1) {
dp[1] = abs(a[1] - a[0]);
return abs(a[1] - a[0]);
}
dp[i] = minn(abs(a[i] - a[i - 1]) + solve(i - 1),
abs(a[i] - a[i - 2]) + solve(i - 2));
return dp[i];
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
IOS;
cin >> n;
f(i, 0, n) { cin >> a[i]; }
f(i, 0, n) { dp[i] = -1; }
ll ans = solve(n - 1);
cout << ans << endl;
return 0;
}
|
delete
| 84 | 88 | 84 | 84 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int dp[10000];
int main() {
int n;
cin >> n;
vector<int> h(n);
for (int i = 0; i < n; i++)
cin >> h[i];
dp[0] = 0;
for (int i = 1; i < n; i++) {
dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
if (i > 1)
dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
}
cout << dp[n - 1] << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
int dp[1000000];
int main() {
int n;
cin >> n;
vector<int> h(n);
for (int i = 0; i < n; i++)
cin >> h[i];
dp[0] = 0;
for (int i = 1; i < n; i++) {
dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
if (i > 1)
dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
}
cout << dp[n - 1] << "\n";
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
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);
cout.tie(NULL);
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
int dp[n];
dp[n - 1] = 0;
dp[n - 2] = abs(a[n - 1] - a[n - 2]);
for (int i = n - 3; i >= 0; i--) {
dp[i] =
min(abs(a[i] - a[i + 1]) + dp[i + 1], abs(a[i] - a[i + 2]) + dp[i + 2]);
}
cout << dp[0];
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
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);
cout.tie(NULL);
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
int dp[n];
dp[n - 1] = 0;
dp[n - 2] = abs(a[n - 1] - a[n - 2]);
for (int i = n - 3; i >= 0; i--) {
dp[i] =
min(abs(a[i] - a[i + 1]) + dp[i + 1], abs(a[i] - a[i + 2]) + dp[i + 2]);
}
cout << dp[0];
}
|
replace
| 5 | 9 | 5 | 11 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
const int MOD = 1000000007;
void print(const std::vector<int> &v) {
std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
std::cout << std::endl;
}
int main() {
int N;
vector<int> h(N);
REP(i, N) cin >> h[i];
vector<int> cost(N, 0);
for (int i = 1; i < N; i++) {
int tcost;
if (i > 1) {
int cost_1 = cost[i - 1] + abs(h[i] - h[i - 1]);
int cost_2 = cost[i - 2] + abs(h[i] - h[i - 2]);
tcost = min(cost_1, cost_2);
} else {
tcost = cost[i - 1] + abs(h[i] - h[i - 1]);
}
cost[i] = tcost;
}
cout << cost[N - 1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
const int MOD = 1000000007;
void print(const std::vector<int> &v) {
std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
std::cout << std::endl;
}
int main() {
int N;
cin >> N;
vector<int> h(N);
REP(i, N) cin >> h[i];
vector<int> cost(N, 0);
for (int i = 1; i < N; i++) {
int tcost;
if (i > 1) {
int cost_1 = cost[i - 1] + abs(h[i] - h[i - 1]);
int cost_2 = cost[i - 2] + abs(h[i] - h[i - 2]);
tcost = min(cost_1, cost_2);
} else {
tcost = cost[i - 1] + abs(h[i] - h[i - 1]);
}
cost[i] = tcost;
}
cout << cost[N - 1] << endl;
return 0;
}
|
insert
| 19 | 19 | 19 | 20 |
0
| |
p03160
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define vb __int128
#define ll long long
#define ld long double
#define full(a) a.begin(), a.end()
#define stoink stack<ll>
#define vec vector<ll>
#define vg vector<vector<ll>>
#define vgw vector < vector<pair<ll, ll>>
#define pa pair<ll, ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pre 0.00000000000000000001
#define inf 1000000000000
#define mod 998244353
vec costdp;
vec height;
ll n;
ll func(ll ind) {
if (ind > n - 1)
return inf;
if (costdp[ind] != -1)
return costdp[ind];
if (ind == n - 1)
return 0;
return min(func(ind + 1) + abs(height[ind + 1] - height[ind]),
func(ind + 2) + abs(height[ind + 2] - height[ind]));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
height.resize(n);
ll i;
costdp.resize(n, -1);
for (i = 0; i < n; i++)
cin >> height[i];
cout << func(0);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define vb __int128
#define ll long long
#define ld long double
#define full(a) a.begin(), a.end()
#define stoink stack<ll>
#define vec vector<ll>
#define vg vector<vector<ll>>
#define vgw vector < vector<pair<ll, ll>>
#define pa pair<ll, ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pre 0.00000000000000000001
#define inf 1000000000000
#define mod 998244353
vec costdp;
vec height;
ll n;
ll func(ll ind) {
if (ind > n - 1)
return inf;
if (costdp[ind] != -1)
return costdp[ind];
if (ind == n - 1)
return 0;
ll res = min(func(ind + 1) + abs(height[ind + 1] - height[ind]),
func(ind + 2) + abs(height[ind + 2] - height[ind]));
return costdp[ind] = res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
height.resize(n);
ll i;
costdp.resize(n, -1);
for (i = 0; i < n; i++)
cin >> height[i];
cout << func(0);
return 0;
}
|
replace
| 28 | 30 | 28 | 31 |
TLE
| |
p03160
|
C++
|
Runtime Error
|
#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;
ll arr[nn];
ll dp[nn];
int main() {
fast();
cin >> n;
for (int i = 0; i < n; i++)
cin >> arr[i];
memset(dp, oo, sizeof dp);
dp[0] = 0;
for (int i = 1; i < n; i++) {
if (i == 1)
dp[i] = abs(arr[i - 1] - arr[i]) + dp[0];
else
dp[i] = min({dp[i - 1] + abs(arr[i - 1] - arr[i]),
dp[i - 2] + abs(arr[i - 2] - arr[i])});
}
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;
ll arr[nn];
ll dp[nn];
int main() {
fast();
cin >> n;
for (int i = 0; i < n; i++)
cin >> arr[i];
memset(dp, oo, sizeof dp);
dp[0] = 0;
for (int i = 1; i < n; i++) {
if (i == 1)
dp[i] = abs(arr[i - 1] - arr[i]) + dp[0];
else
dp[i] = min({dp[i - 1] + abs(arr[i - 1] - arr[i]),
dp[i - 2] + abs(arr[i - 2] - arr[i])});
}
cout << dp[n - 1] << endl;
return 0;
}
|
replace
| 32 | 33 | 32 | 33 |
0
| |
p03160
|
C++
|
Runtime Error
|
#define _USE_MATH_DEFINES // M_PI
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
using ll = long long;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define rREP(i, a, n) for (int(i) = (n)-1; (i) >= (a); --(i))
#define all(x) (x).begin(), (x).end()
#define out(y, x, h, w) (y) < 0 || (x) < 0 || (y) >= (h) || (x) >= (w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;
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;
}
inline void init() {
cin.tie(nullptr);
cout.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
int main() {
init();
int N;
cin >> N;
vector<int> h(N);
rep(i, N) cin >> h[i];
int dp[10001];
fill(dp, dp + 10001, INF);
dp[0] = 0;
dp[1] = abs(h[0] - h[1]);
REP(i, 2, N) {
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
}
cout << dp[N - 1] << "\n";
return 0;
}
|
#define _USE_MATH_DEFINES // M_PI
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
using ll = long long;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define rREP(i, a, n) for (int(i) = (n)-1; (i) >= (a); --(i))
#define all(x) (x).begin(), (x).end()
#define out(y, x, h, w) (y) < 0 || (x) < 0 || (y) >= (h) || (x) >= (w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;
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;
}
inline void init() {
cin.tie(nullptr);
cout.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
int main() {
init();
int N;
cin >> N;
vector<int> h(N);
rep(i, N) cin >> h[i];
vector<int> dp(N, INF);
dp[0] = 0;
dp[1] = abs(h[0] - h[1]);
REP(i, 2, N) {
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
}
cout << dp[N - 1] << "\n";
return 0;
}
|
replace
| 41 | 43 | 41 | 42 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <string>
#include <vector>
using namespace std::chrono;
using namespace std;
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define ll long long
bool isPowerOfTwo(ll x) {
/* First x in the below expression is for the case when x is 0 */
return x && (!(x & (x - 1)));
}
bool SameSign(ll x, ll y) { return (x >= 0) ^ (y < 0); }
ll gcd(ll u, ll v) {
ll shift;
if (u == 0)
return v;
if (v == 0)
return u;
shift = __builtin_ctz(u | v);
u >>= __builtin_ctz(u);
do {
v >>= __builtin_ctz(v);
if (u > v) {
ll t = v;
v = u;
u = t;
}
v = v - u;
} while (v != 0);
return u << shift;
}
ll lcm(ll u, ll v) { return u * v / gcd(u, v); }
int isPower(int A) {
int i = 2;
int n;
if (A == 1) {
return true;
} else {
while (1) {
n = A;
int count = 0;
while (n % i == 0) {
n = n / i;
count++;
}
if (n == 1 && count > 1) {
return true;
} else if (n == 1 && count <= 1)
return false;
i++;
}
return false;
}
}
#define PI 3.14159265358979323846
// 30 10 60 10 60 50
// dp[6]=dp[5]+10;
// dp[5]=dp[3]+0;
// dp[3]=dp[1]+30;
// dp[1]=0;
int dp[100] = {0};
int main() {
int n;
cin >> n;
int a[n];
rep(i, 0, n) cin >> a[i];
dp[0] = 0;
dp[1] = abs(a[1] - a[0]);
rep(i, 2, n) {
dp[i] =
min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
}
cout << dp[n - 1] << endl;
}
|
#include <bits/stdc++.h>
#include <string>
#include <vector>
using namespace std::chrono;
using namespace std;
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define ll long long
bool isPowerOfTwo(ll x) {
/* First x in the below expression is for the case when x is 0 */
return x && (!(x & (x - 1)));
}
bool SameSign(ll x, ll y) { return (x >= 0) ^ (y < 0); }
ll gcd(ll u, ll v) {
ll shift;
if (u == 0)
return v;
if (v == 0)
return u;
shift = __builtin_ctz(u | v);
u >>= __builtin_ctz(u);
do {
v >>= __builtin_ctz(v);
if (u > v) {
ll t = v;
v = u;
u = t;
}
v = v - u;
} while (v != 0);
return u << shift;
}
ll lcm(ll u, ll v) { return u * v / gcd(u, v); }
int isPower(int A) {
int i = 2;
int n;
if (A == 1) {
return true;
} else {
while (1) {
n = A;
int count = 0;
while (n % i == 0) {
n = n / i;
count++;
}
if (n == 1 && count > 1) {
return true;
} else if (n == 1 && count <= 1)
return false;
i++;
}
return false;
}
}
#define PI 3.14159265358979323846
// 30 10 60 10 60 50
// dp[6]=dp[5]+10;
// dp[5]=dp[3]+0;
// dp[3]=dp[1]+30;
// dp[1]=0;
int dp[100050] = {0};
int main() {
int n;
cin >> n;
int a[n];
rep(i, 0, n) cin >> a[i];
dp[0] = 0;
dp[1] = abs(a[1] - a[0]);
rep(i, 2, n) {
dp[i] =
min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
}
cout << dp[n - 1] << endl;
}
|
replace
| 68 | 69 | 68 | 69 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define rep(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
// rep(i,1,10) is from 1 to 9 and rep(I,10,1) is from 9 to 1
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define mi multiset<int>
#define mii multiset<pii>
#define what_is(x) cerr << #x << " is " << x << "\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) \
for (auto x : a) \
cout << x << " ";
// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag,
// tree_order_statistics_node_update>
// using namespace __gnu_pbds;
using namespace std;
int lcm(int a, int b) { return (a * (b / __gcd(a, b))); }
int modp(int a, int n) {
if (n == 0)
return 1;
if (n == 1)
return a;
int res = modp(a, n / 2);
if (n % 2 == 0)
return (res * res);
else
return (a * res * res);
}
vi adj[1000005], ans;
vector<bool> vis(1000005, false);
map<pii, int> problem, elected;
int check = 0;
bool dfs(int s) {
bool y = 0;
vis[s] = true;
for (int u : adj[s]) {
if (!vis[u]) {
vis[u] = true;
if (problem[{u, s}] || problem[{s, u}]) {
y = 1;
if (!dfs(u)) {
ans.pb(u);
}
} else {
if (dfs(u)) {
y = 1;
}
}
}
}
return y;
}
void solve() {
int t, n, m, i, k, r, l, u, v, w, j, s, sum = 0, pos, flag = 0, count = 0;
string S, T, U;
// int f,g,d;
cin >> n;
vi a(n);
rep(i, 0, n) cin >> a[i];
vi dp(n, 1000000);
dp[0] = 0;
dp[1] = abs(a[1] - a[0]);
rep(i, 2, n) {
dp[i] =
min(dp[i - 2] + abs(a[i - 2] - a[i]), dp[i - 1] + abs(a[i] - a[i - 1]));
}
cout << dp[n - 1];
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>>t;
while (t--) {
solve();
cout << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define rep(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
// rep(i,1,10) is from 1 to 9 and rep(I,10,1) is from 9 to 1
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define mi multiset<int>
#define mii multiset<pii>
#define what_is(x) cerr << #x << " is " << x << "\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) \
for (auto x : a) \
cout << x << " ";
// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag,
// tree_order_statistics_node_update>
// using namespace __gnu_pbds;
using namespace std;
int lcm(int a, int b) { return (a * (b / __gcd(a, b))); }
int modp(int a, int n) {
if (n == 0)
return 1;
if (n == 1)
return a;
int res = modp(a, n / 2);
if (n % 2 == 0)
return (res * res);
else
return (a * res * res);
}
vi adj[1000005], ans;
vector<bool> vis(1000005, false);
map<pii, int> problem, elected;
int check = 0;
bool dfs(int s) {
bool y = 0;
vis[s] = true;
for (int u : adj[s]) {
if (!vis[u]) {
vis[u] = true;
if (problem[{u, s}] || problem[{s, u}]) {
y = 1;
if (!dfs(u)) {
ans.pb(u);
}
} else {
if (dfs(u)) {
y = 1;
}
}
}
}
return y;
}
void solve() {
int t, n, m, i, k, r, l, u, v, w, j, s, sum = 0, pos, flag = 0, count = 0;
string S, T, U;
// int f,g,d;
cin >> n;
vi a(n);
rep(i, 0, n) cin >> a[i];
vi dp(n, 1000000);
dp[0] = 0;
dp[1] = abs(a[1] - a[0]);
rep(i, 2, n) {
dp[i] =
min(dp[i - 2] + abs(a[i - 2] - a[i]), dp[i - 1] + abs(a[i] - a[i - 1]));
}
cout << dp[n - 1];
}
signed main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>>t;
while (t--) {
solve();
cout << "\n";
}
return 0;
}
|
replace
| 94 | 98 | 94 | 98 |
-6
|
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int minCost(int *arr, int n, int curr, int *dp) {
if (curr == n)
return 0;
if (curr == n - 1) {
return abs(arr[curr] - arr[n]);
}
if (dp[curr] != -1)
return dp[curr];
int oneJump = abs(arr[curr] - arr[curr + 1]) + minCost(arr, n, curr + 1, dp);
int twoJump = abs(arr[curr] - arr[curr + 2]) + minCost(arr, n, curr + 2, dp);
dp[curr] = min(oneJump, twoJump);
return dp[curr];
}
int main() {
int n;
cin >> n;
int *arr = new int[n + 1];
for (int i = 1; i <= n; i++) {
int h;
cin >> h;
arr[i] = h;
}
int *dp = new int[n + 1];
memset(dp, -1, sizeof(dp[0]) * (n + 1));
return minCost(arr, n, 1, dp);
}
|
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int minCost(int *arr, int n, int curr, int *dp) {
if (curr == n)
return 0;
if (curr == n - 1) {
return abs(arr[curr] - arr[n]);
}
if (dp[curr] != -1)
return dp[curr];
int oneJump = abs(arr[curr] - arr[curr + 1]) + minCost(arr, n, curr + 1, dp);
int twoJump = abs(arr[curr] - arr[curr + 2]) + minCost(arr, n, curr + 2, dp);
dp[curr] = min(oneJump, twoJump);
return dp[curr];
}
int main() {
int n;
cin >> n;
int *arr = new int[n + 1];
for (int i = 1; i <= n; i++) {
int h;
cin >> h;
arr[i] = h;
}
int *dp = new int[n + 1];
memset(dp, -1, sizeof(dp[0]) * (n + 1));
cout << minCost(arr, n, 1, dp) << endl;
return 0;
}
|
replace
| 33 | 34 | 33 | 35 |
30
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define mod 1000000007
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast;
ll n;
cin >> n;
ll a[n], i;
rep(i, 0, n) { cin >> a[i]; }
ll dp[n];
dp[0] = 0;
dp[1] = abs(a[1] - a[0]);
for (i = 2; i < n; i++) {
dp[i] =
min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
}
cout << dp[n - 1] << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define mod 1000000007
int main() {
fast;
ll n;
cin >> n;
ll a[n], i;
rep(i, 0, n) { cin >> a[i]; }
ll dp[n];
dp[0] = 0;
dp[1] = abs(a[1] - a[0]);
for (i = 2; i < n; i++) {
dp[i] =
min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
}
cout << dp[n - 1] << "\n";
}
|
delete
| 11 | 15 | 11 | 11 |
-11
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
long long n, m;
cin >> n;
vector<long long> hh(10009, 0);
vector<long long> hhh(10005, 0);
for (int i = 0; i < n; i++) {
cin >> hh.at(i);
}
hhh.at(1) = abs(hh.at(0) - hh.at(1));
for (int i = 2; i < n; i++) {
hhh.at(i) = min(hhh.at(i - 2) + abs(hh.at(i) - hh.at(i - 2)),
hhh.at(i - 1) + abs(hh.at(i) - hh.at(i - 1)));
if (i == n - 1) {
}
}
cout << hhh.at(n - 1) << '\n';
return (0);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
long long n, m;
cin >> n;
vector<long long> hh(100000, 0);
vector<long long> hhh(100000, 0);
for (int i = 0; i < n; i++) {
cin >> hh.at(i);
}
hhh.at(1) = abs(hh.at(0) - hh.at(1));
for (int i = 2; i < n; i++) {
hhh.at(i) = min(hhh.at(i - 2) + abs(hh.at(i) - hh.at(i - 2)),
hhh.at(i - 1) + abs(hh.at(i) - hh.at(i - 1)));
if (i == n - 1) {
}
}
cout << hhh.at(n - 1) << '\n';
return (0);
}
|
replace
| 7 | 9 | 7 | 9 |
0
| |
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
//////////////////
#ifdef DEBUG
#include "debug.h"
#define dump(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
<< " ", \
dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
//////////////////
#define int long long
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
//*
#define mod \
1000000007 /*/ \
#define mod 998244353 //*/
typedef pair<int, int> P;
#define INF (1LL << 60)
void solve() {
int N;
cin >> N;
vector<int> h(N + 1);
rep(i, N) cin >> h[i + 1];
vector<int> dp(N + 1, INF);
dp[1] = 0;
for (int i = 1; i < N; i++) {
chmin(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
chmin(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
}
cout << dp[N] << endl;
}
signed main() {
cout << fixed << setprecision(18);
// cerr << fixed << setprecision(18);
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
//////////////////
#ifdef DEBUG
#include "debug.h"
#define dump(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
<< " ", \
dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
//////////////////
#define int long long
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
//*
#define mod \
1000000007 /*/ \
#define mod 998244353 //*/
typedef pair<int, int> P;
#define INF (1LL << 60)
void solve() {
int N;
cin >> N;
vector<int> h(N + 1);
rep(i, N) cin >> h[i + 1];
vector<int> dp(N + 2, INF);
dp[1] = 0;
for (int i = 1; i < N; i++) {
chmin(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
chmin(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
}
cout << dp[N] << endl;
}
signed main() {
cout << fixed << setprecision(18);
// cerr << fixed << setprecision(18);
solve();
}
|
replace
| 75 | 76 | 75 | 76 |
-6
|
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p03160
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <iostream>
using namespace std;
#define ll long long
ll dp[100];
ll arr[100] = {0};
int n = 0;
ll solve(int i) {
if (i == n - 1)
return 0;
if (dp[i] != -1)
return dp[i];
ll op1, op2;
op1 = abs(arr[i] - arr[i + 1]) + solve(i + 1);
op2 = INT_MAX;
if (i + 2 < n)
op2 = abs(arr[i] - arr[i + 2]) + solve(i + 2);
return dp[i] = min(op1, op2);
}
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> arr[i];
memset(dp, -1, sizeof(dp));
cout << "\n" << solve(0);
return 0;
}
|
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <iostream>
using namespace std;
#define ll long long
ll dp[100009];
ll arr[100009] = {0};
int n = 0;
ll solve(int i) {
if (i == n - 1)
return 0;
if (dp[i] != -1)
return dp[i];
ll op1, op2;
op1 = abs(arr[i] - arr[i + 1]) + solve(i + 1);
op2 = INT_MAX;
if (i + 2 < n)
op2 = abs(arr[i] - arr[i + 2]) + solve(i + 2);
return dp[i] = min(op1, op2);
}
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> arr[i];
memset(dp, -1, sizeof(dp));
cout << "\n" << solve(0);
return 0;
}
|
replace
| 6 | 8 | 6 | 8 |
0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.