CSES - APIO 2007 - Results
Submission details
Task:Backup
Sender:henrikaalto
Submission time:2019-03-07 17:45:00 +0200
Language:C++
Status:READY
Result:30
Feedback
groupverdictscore
#1ACCEPTED30
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.04 s1, 2, 3details
#2ACCEPTED0.19 s1, 2, 3details
#30.02 s3details
#40.02 s3details
#5ACCEPTED0.20 s1, 2, 3details
#60.02 s2, 3details
#7ACCEPTED0.14 s1, 2, 3details
#8ACCEPTED0.20 s1, 2, 3details
#90.03 s2, 3details
#100.03 s2, 3details
#110.02 s3details
#120.02 s3details
#130.01 s3details
#14ACCEPTED0.15 s1, 2, 3details
#150.01 s2, 3details
#160.01 s3details
#170.03 s3details
#180.01 s2, 3details
#190.01 s2, 3details
#200.01 s3details

Compiler report

input/code.cpp: In function 'long int f(int)':
input/code.cpp:28:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(v.size()<k) return 1e18;
      ~~~~~~~~^~

Code

#pragma GCC optimize("unroll-loops,O3")
#include<bits/stdc++.h>
using namespace std;
int n,k;
long d[123];
long f(int x) {
  vector<long> v;
  int it = -1;
  for(int i=0;i<n;i++) {
    if(x & (1<<i)) {
      if(it&1) {
        it += 2;
      }
      else {
        it += 3;
      }
    }
    else {
      if(it&1) {
        it += 3;
      } else {
        it += 2;
      }
    }
    if(it>=n) break;
    v.push_back(d[it]-d[it-1]);
  }
  if(v.size()<k) return 1e18;
  sort(v.begin(),v.end());
  long sum = 0;
  for(int i=0;i<k;i++)
    sum += v[i];
  return sum;
} 

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  cin >> n >> k;
  assert(n<=20);
  for(int i=0;i<n;i++) cin >> d[i];
  long res = 1e18;
  for(int i=0;i<(1<<20);i++) {
    res = min(res,f(i));
  }
  cout << res << "\n";
}

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:

input
100000 49000
29983
53806
76909
106815
...

correct output
411321413

user output
(empty)

Error:
code: input/code.cpp:39: int main(): Assertion `n<=20' failed.

Test 4

Group: 3

Verdict:

input
100000 30000
29983
53806
76909
106815
...

correct output
100755932

user output
(empty)

Error:
code: input/code.cpp:39: int main(): Assertion `n<=20' failed.

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:

input
10000 4999
168328
266967
462469
639689
...

correct output
492516409

user output
(empty)

Error:
code: input/code.cpp:39: int main(): Assertion `n<=20' failed.

Test 7

Group: 1, 2, 3

Verdict: ACCEPTED

input
10 4
165
375
439
456
...

correct output
44

user output
44

Test 8

Group: 1, 2, 3

Verdict: ACCEPTED

input
20 9
4336
4500
4552
4702
...

correct output
773

user output
773

Test 9

Group: 2, 3

Verdict:

input
2001 1000
1230
1440
1630
2230
...

correct output
493503

user output
(empty)

Error:
code: input/code.cpp:39: int main(): Assertion `n<=20' failed.

Test 10

Group: 2, 3

Verdict:

input
10000 3000
245408
417449
650973
863296
...

correct output
101056127

user output
(empty)

Error:
code: input/code.cpp:39: int main(): Assertion `n<=20' failed.

Test 11

Group: 3

Verdict:

input
50000 20000
37035
37042
37046
37052
...

correct output
129968

user output
(empty)

Error:
code: input/code.cpp:39: int main(): Assertion `n<=20' failed.

Test 12

Group: 3

Verdict:

input
99999 48000
15929
43928
65765
86730
...

correct output
375524431

user output
(empty)

Error:
code: input/code.cpp:39: int main(): Assertion `n<=20' failed.

Test 13

Group: 3

Verdict:

input
100000 1000
536
9214
34619
53734
...

correct output
75975

user output
(empty)

Error:
code: input/code.cpp:39: int main(): Assertion `n<=20' failed.

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:

input
100 45
3712
13742
17394
19428
...

correct output
140256

user output
(empty)

Error:
code: input/code.cpp:39: int main(): Assertion `n<=20' failed.

Test 16

Group: 3

Verdict:

input
20000 400
3174
3175
3176
3179
...

correct output
803105

user output
(empty)

Error:
code: input/code.cpp:39: int main(): Assertion `n<=20' failed.

Test 17

Group: 3

Verdict:

input
100000 49000
3605
14510
18001
20881
...

correct output
162316123

user output
(empty)

Error:
code: input/code.cpp:39: int main(): Assertion `n<=20' failed.

Test 18

Group: 2, 3

Verdict:

input
100 50
0
1000000
1000002
1000005
...

correct output
1002499

user output
(empty)

Error:
code: input/code.cpp:39: int main(): Assertion `n<=20' failed.

Test 19

Group: 2, 3

Verdict:

input
1000 500
0
1000000
1000002
1000005
...

correct output
1249999

user output
(empty)

Error:
code: input/code.cpp:39: int main(): Assertion `n<=20' failed.

Test 20

Group: 3

Verdict:

input
100000 49494
123
65659
98427
114811
...

correct output
250954854

user output
(empty)

Error:
code: input/code.cpp:39: int main(): Assertion `n<=20' failed.