| Task: | Backup |
| Sender: | Yytsi |
| Submission time: | 2019-03-07 16:47:09 +0200 |
| Language: | C++ |
| Status: | READY |
| Result: | 0 |
| group | verdict | score |
|---|---|---|
| #1 | WRONG ANSWER | 0 |
| #2 | RUNTIME ERROR | 0 |
| #3 | RUNTIME ERROR | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.02 s | 1, 2, 3 | details |
| #2 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
| #3 | RUNTIME ERROR | 0.02 s | 3 | details |
| #4 | RUNTIME ERROR | 0.01 s | 3 | details |
| #5 | ACCEPTED | 0.02 s | 1, 2, 3 | details |
| #6 | RUNTIME ERROR | 0.02 s | 2, 3 | details |
| #7 | WRONG ANSWER | 0.02 s | 1, 2, 3 | details |
| #8 | WRONG ANSWER | 0.03 s | 1, 2, 3 | details |
| #9 | RUNTIME ERROR | 0.02 s | 2, 3 | details |
| #10 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
| #11 | RUNTIME ERROR | 0.02 s | 3 | details |
| #12 | RUNTIME ERROR | 0.02 s | 3 | details |
| #13 | RUNTIME ERROR | 0.01 s | 3 | details |
| #14 | ACCEPTED | 0.02 s | 1, 2, 3 | details |
| #15 | RUNTIME ERROR | 0.02 s | 2, 3 | details |
| #16 | RUNTIME ERROR | 0.02 s | 3 | details |
| #17 | RUNTIME ERROR | 0.03 s | 3 | details |
| #18 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
| #19 | RUNTIME ERROR | 0.01 s | 2, 3 | details |
| #20 | RUNTIME ERROR | 0.02 s | 3 | details |
Compiler report
input/code.cpp: In function 'll f(int, int)':
input/code.cpp:6:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define FOR(i, a, b) for (int i=a; i<(b); i++)
^
input/code.cpp:43:2: note: in expansion of macro 'FOR'
FOR(i,0,pnts.size()) {
^~~Code
// QAQ MIKSI EI TOIMI :'(
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define IO ios_base::sync_with_stdio(0); cin.tie(0)
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define N 25
bool able[N];
ll val[N];
int n, k;
ll f(int p, int moves) {
if (p <= 0 && moves == 0) return 0;
if (moves == 0) return 0;
if (p == 0 && moves > 0) return (ll)999999999999999LL;
// s => able to pair with
vector<int> pnts;
for (int i = p+1; i <= n; i++) {
if (able[i]) {
pnts.pb(i);
}
}
if (pnts.size() == 0) {
return f(p-1, moves);
}
ll r = f(p-1, moves);
able[p] = false;
FOR(i,0,pnts.size()) {
int pnt = pnts[i];
able[pnt] = false;
r = min(f(p-1, moves-1) + abs(val[pnt] - val[p]), r);
able[pnt] = true;
}
able[p] = true;
return r;
}
ll dp[25][25]; // dp[p][k]
int main() {
IO; cin>>n>>k;
FOR(i,1,n+1) able[i] = true;
FOR(i,1,n+1) cin>>val[i];
FOR(p,1,n+2) FOR(m,0,22) dp[p][m] = 999999999999999999LL;
dp[1][k] = 0;
for (int p = 1; p < n; p++) {
for (int moves = k; moves >= 1; moves--) {
dp[p + 2][moves-1] = min(dp[p+2][moves-1], dp[p][moves] + abs(val[p] - val[p+1]));
}
}
ll m = 999999999999999999LL;
FOR(p,2,n+2) {
m = min(dp[p][0], m);
}
cout<<m;
}Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
| input |
|---|
| 2 1 0 1000000000 |
| correct output |
|---|
| 1000000000 |
| user output |
|---|
| 1000000000 |
Test 2
Group: 1, 2, 3
Verdict: ACCEPTED
| input |
|---|
| 17 8 101266 101394 101458 101490 ... |
| correct output |
|---|
| 340 |
| user output |
|---|
| 340 |
Test 3
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 49000 29983 53806 76909 106815 ... |
| correct output |
|---|
| 411321413 |
| user output |
|---|
| (empty) |
Test 4
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 30000 29983 53806 76909 106815 ... |
| correct output |
|---|
| 100755932 |
| user output |
|---|
| (empty) |
Test 5
Group: 1, 2, 3
Verdict: ACCEPTED
| input |
|---|
| 20 10 126229031 250138471 333910089 443521720 ... |
| correct output |
|---|
| 537092323 |
| user output |
|---|
| 537092323 |
Test 6
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 10000 4999 168328 266967 462469 639689 ... |
| correct output |
|---|
| 492516409 |
| user output |
|---|
| (empty) |
Test 7
Group: 1, 2, 3
Verdict: WRONG ANSWER
| input |
|---|
| 10 4 165 375 439 456 ... |
| correct output |
|---|
| 44 |
| user output |
|---|
| 243 |
Test 8
Group: 1, 2, 3
Verdict: WRONG ANSWER
| input |
|---|
| 20 9 4336 4500 4552 4702 ... |
| correct output |
|---|
| 773 |
| user output |
|---|
| 885 |
Test 9
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 2001 1000 1230 1440 1630 2230 ... |
| correct output |
|---|
| 493503 |
| user output |
|---|
| (empty) |
Test 10
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 10000 3000 245408 417449 650973 863296 ... |
| correct output |
|---|
| 101056127 |
| user output |
|---|
| (empty) |
Test 11
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 50000 20000 37035 37042 37046 37052 ... |
| correct output |
|---|
| 129968 |
| user output |
|---|
| (empty) |
Test 12
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 99999 48000 15929 43928 65765 86730 ... |
| correct output |
|---|
| 375524431 |
| user output |
|---|
| (empty) |
Test 13
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 1000 536 9214 34619 53734 ... |
| correct output |
|---|
| 75975 |
| user output |
|---|
| (empty) |
Test 14
Group: 1, 2, 3
Verdict: ACCEPTED
| input |
|---|
| 10 4 5851 5854 5856 5859 ... |
| correct output |
|---|
| 2664 |
| user output |
|---|
| 2664 |
Test 15
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 45 3712 13742 17394 19428 ... |
| correct output |
|---|
| 140256 |
| user output |
|---|
| (empty) |
Test 16
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 20000 400 3174 3175 3176 3179 ... |
| correct output |
|---|
| 803105 |
| user output |
|---|
| (empty) |
Test 17
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 49000 3605 14510 18001 20881 ... |
| correct output |
|---|
| 162316123 |
| user output |
|---|
| (empty) |
Test 18
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100 50 0 1000000 1000002 1000005 ... |
| correct output |
|---|
| 1002499 |
| user output |
|---|
| (empty) |
Test 19
Group: 2, 3
Verdict: RUNTIME ERROR
| input |
|---|
| 1000 500 0 1000000 1000002 1000005 ... |
| correct output |
|---|
| 1249999 |
| user output |
|---|
| (empty) |
Test 20
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 49494 123 65659 98427 114811 ... |
| correct output |
|---|
| 250954854 |
| user output |
|---|
| (empty) |
