CSES - Datatähti 2019 alku - Results
Submission details
Task:Kolikot
Sender:jaakkonen
Submission time:2018-10-07 02:52:01 +0300
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1details
#20.01 s1details
#30.01 s1details
#40.03 s1details
#50.01 s1details
#60.01 s1details
#70.02 s1details
#80.02 s1details
#90.01 s1details
#100.01 s1details
#110.01 s2details
#120.01 s2details
#130.02 s2details
#140.02 s2details
#150.03 s2details
#160.03 s2details
#170.02 s2details
#180.02 s2details
#190.01 s2details
#200.01 s2details
#210.01 s3details
#220.01 s3details
#230.01 s3details
#240.03 s3details
#250.12 s3details
#26--3details
#27--3details
#28--3details
#29--3details
#30--3details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:32:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (index != arr.size()){
            ~~~~~~^~~~~~~~~~~~~
input/code.cpp:40:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(active_nums.size() > k){
                ~~~~~~~~~~~~~~~~~~~^~~
input/code.cpp:55:28: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long int' [-Wformat=]
     printf("%d\n",subarrays);
                            ^
input/code.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%ld",&n);
     ~~~~~^~~~~~~~~~
input/code.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%ld",&k);
     ~~~~~^~~~~~~~~~
input/code.cpp:19:14: warning: ig

Code

#include<deque>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main(){
    deque<long> arr;
    long k;
    long n;
    //k = 3;
    //n = 8;
    //arr = {1, 2, 1, 1, 1, 3, 1, 4};

    
    scanf("%ld",&n);
    scanf("%ld",&k);
    
    long temp;
    for(int i=0;i<n;i++){
        scanf("%ld",&temp);
        arr.push_back(temp);
    }    

    deque<long> active_nums;
    active_nums.resize(k);
    deque<long>::iterator it;
    long subarrays = 0;
    long index = 0;
    long curr_num;
    long num_to_remove;
    long removed_index;

    while (index != arr.size()){
        curr_num = arr[index];
        it = find(active_nums.begin(), active_nums.end(), curr_num);
        if(it != active_nums.end()){
            active_nums.erase(it);
            active_nums.push_back(curr_num);
        }else{
            active_nums.push_back(curr_num);
            if(active_nums.size() > k){
                for(long x : active_nums) {num_to_remove = x; break;}
                //num_to_remove = arr.front();
                active_nums.pop_front();
                removed_index = arr.size() - (find(arr.rbegin() + arr.size() - index, arr.rend(), num_to_remove) - arr.rbegin()) - 1;
                //subarrays += (pow(index, 2)+index)/2;
                //subarrays -= (pow(index-removed_index-1,2)+index-removed_index-1)/2;
                subarrays += (removed_index*(2*index-removed_index-1)+2*index)/2;
                arr.erase(arr.begin(), arr.begin()+removed_index+1);
                index = 0;
            }
        }
        index++;
    }
    subarrays += (arr.size()+1)*arr.size()/2;
    printf("%d\n",subarrays);
}

Test details

Test 1

Group: 1

Verdict:

input
1

correct output
1

user output
1

Test 2

Group: 1

Verdict:

input
2

correct output
1

user output
2

Test 3

Group: 1

Verdict:

input
3

correct output
2
1 2 

user output
3

Test 4

Group: 1

Verdict:

input
4

correct output
2
1 3 

user output
4

Test 5

Group: 1

Verdict:

input
5

correct output
2
1 4 

user output
15

Test 6

Group: 1

Verdict:

input
6

correct output
3
1 2 3 

user output
6

Test 7

Group: 1

Verdict:

input
7

correct output
3
1 2 4 

user output
7

Test 8

Group: 1

Verdict:

input
8

correct output
3
1 2 5 

user output
8

Test 9

Group: 1

Verdict:

input
9

correct output
3
1 2 6 

user output
45

Test 10

Group: 1

Verdict:

input
10

correct output
4
1 2 3 4 

user output
10

Test 11

Group: 2

Verdict:

input
11

correct output
4
1 2 3 5 

user output
11

Test 12

Group: 2

Verdict:

input
54

correct output
9
1 2 3 4 5 6 7 8 18 

user output
1485

Test 13

Group: 2

Verdict:

input
55

correct output
10
1 2 3 4 5 6 7 8 9 10 

user output
55

Test 14

Group: 2

Verdict:

input
56

correct output
10
1 2 3 4 5 6 7 8 9 11 

user output
1596

Test 15

Group: 2

Verdict:

input
123

correct output
15
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
123

Test 16

Group: 2

Verdict:

input
819

correct output
39
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
819

Test 17

Group: 2

Verdict:

input
820

correct output
40
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
820

Test 18

Group: 2

Verdict:

input
821

correct output
40
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
821

Test 19

Group: 2

Verdict:

input
999

correct output
44
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
999

Test 20

Group: 2

Verdict:

input
1000

correct output
44
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
500500

Test 21

Group: 3

Verdict:

input
1274

correct output
49
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1274

Test 22

Group: 3

Verdict:

input
1275

correct output
50
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1275

Test 23

Group: 3

Verdict:

input
1276

correct output
50
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1276

Test 24

Group: 3

Verdict:

input
12345

correct output
156
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
12345

Test 25

Group: 3

Verdict:

input
123456

correct output
496
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
123456

Test 26

Group: 3

Verdict:

input
10000000

correct output
4471
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)

Test 27

Group: 3

Verdict:

input
100000000

correct output
14141
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)

Test 28

Group: 3

Verdict:

input
500000000

correct output
31622
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)

Test 29

Group: 3

Verdict:

input
999999999

correct output
44720
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)

Test 30

Group: 3

Verdict:

input
1000000000

correct output
44720
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
(empty)