CSES - E4590 2018 2 - Results
Submission details
Task:Coffee shops
Sender:natalia
Submission time:2018-09-22 14:32:28 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1UNKNOWN--details
#2UNKNOWN--details
#3UNKNOWN--details
#4UNKNOWN--details
#5UNKNOWN--details
#6UNKNOWN--details
#7UNKNOWN--details
#8UNKNOWN--details
#9UNKNOWN--details
#10UNKNOWN--details
#11UNKNOWN--details
#12UNKNOWN--details
#13UNKNOWN--details
#14UNKNOWN--details
#15UNKNOWN--details
#16UNKNOWN--details
#17UNKNOWN--details
#18UNKNOWN--details

Compiler report

input/code.cpp: In function 'int main(int, const char**)':
input/code.cpp:18:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < n; i++)
                    ~~^~~
input/code.cpp:47:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 3; i < n; i++){
                    ~~^~~

Code

#include <iostream>
#include <string>
#include <limits.h>

/*
inline int min(int x, int y){
    return y ^ ((x ^ y) & -(x < y));
}
*/

int main(int argc, const char * argv[]) {
    
    unsigned long n;
    std::cin >> n;
    
    int* data = (int*)malloc(n * sizeof(int));
    
    for(int i = 0; i < n; i++)
        std::cin >> data[i];
    
    if(n == 1){
        std::cout << data[0] << "\n";
        return 0;
    }
    
    if(n == 2){
        std::cout << std::min(data[0], data[1]) << "\n";
        return 0;
    }
    
    int* op_0_1_0 = (int*)malloc(n * sizeof(int));
    int* op_1_0_0 = (int*)malloc(n * sizeof(int));
    int* op_1_1_0 = (int*)malloc(n * sizeof(int));
    
    int* op_0_0_1 = (int*)malloc(n * sizeof(int));
    int* op_0_1_1 = (int*)malloc(n * sizeof(int));
    int* op_1_0_1 = (int*)malloc(n * sizeof(int));
    
    op_0_1_0[2] = data[1];
    op_1_0_0[2] = data[0];
    op_1_1_0[2] = data[0] + data[1];
    
    op_0_0_1[2] = data[0] + data[2];
    op_0_1_1[2] = data[1] + data[2];
    op_1_0_1[2] = data[0] + data[2];
    
    for(int i = 3; i < n; i++){
        op_0_1_0[i] = std::min(op_0_0_1[i - 1], op_1_0_1[i - 1]);
        op_1_0_0[i] = std::min(op_1_1_0[i - 1], op_0_1_0[i - 1]);
        op_1_1_0[i] = op_0_1_1[i - 1];
        
        op_0_0_1[i] = op_1_0_0[i - 1] + data[i];
        op_0_1_1[i] = std::min(op_1_0_1[i - 1], op_0_0_1[i - 1]) + data[i];
        op_1_0_1[i] = std::min(op_0_1_0[i - 1], op_1_1_0[i - 1]) + data[i];
    }
    
    op_1_0_0[n - 1] += data[n - 1];

    /*
    std::cout << "op_0_1_0\n";
    for(int i = 0; i < n; i++)
        std::cout << op_0_1_0[i] << "\t";
    std::cout << "\n";
    
    std::cout << "op_1_0_0\n";
    for(int i = 0; i < n; i++)
        std::cout << op_1_0_0[i] << "\t";
    std::cout << "\n";
    
    std::cout << "op_1_1_0\n";
    for(int i = 0; i < n; i++)
        std::cout << op_1_1_0[i] << "\t";
    std::cout << "\n";
    
    std::cout << "op_0_0_1\n";
    for(int i = 0; i < n; i++)
        std::cout << op_0_0_1[i] << "\t";
    std::cout << "\n";
    
    std::cout << "op_0_1_1\n";
    for(int i = 0; i < n; i++)
        std::cout << op_0_1_1[i] << "\t";
    std::cout << "\n";
    
    std::cout << "op_1_0_1\n";
    for(int i = 0; i < n; i++)
        std::cout << op_1_0_1[i] << "\t";
    std::cout << "\n";
     */
    
    int min1 = std::min(op_0_1_0[n - 1], op_1_0_0[n - 1]);
    int min2 = std::min(op_1_1_0[n - 1], op_0_0_1[n - 1]);
    int min3 = std::min(op_0_1_1[n - 1], op_1_0_1[n - 1]);
    
    int result = std::min(min1, std::min(min2, min3));
    
    std::cout << result << "\n";
    
    
    return 0;
}

Test details

Test 1

Verdict: UNKNOWN

input
9
1 1 1000 1 1000 1000 1 1 1

correct output
4

user output
(not available)

Test 2

Verdict: UNKNOWN

input
100
5 6 3 10 10 1 8 3 8 4 3 1 10 4...

correct output
152

user output
(not available)

Test 3

Verdict: UNKNOWN

input
1000
4 5 5 7 3 4 9 5 1 5 9 9 1 9 2 ...

correct output
1383

user output
(not available)

Test 4

Verdict: UNKNOWN

input
10000
10 8 9 6 3 5 2 9 4 7 6 3 1 1 2...

correct output
13686

user output
(not available)

Test 5

Verdict: UNKNOWN

input
100000
9 7 6 1 9 9 9 4 7 9 6 5 9 1 8 ...

correct output
136447

user output
(not available)

Test 6

Verdict: UNKNOWN

input
1000000
2 7 4 4 5 6 5 9 5 9 1 6 8 3 5 ...

correct output
1355562

user output
(not available)

Test 7

Verdict: UNKNOWN

input
1000000
4 8 3 6 4 5 4 9 3 6 8 7 8 1 5 ...

correct output
1358066

user output
(not available)

Test 8

Verdict: UNKNOWN

input
1000000
4 5 5 9 3 2 2 8 5 9 6 4 6 7 10...

correct output
1356381

user output
(not available)

Test 9

Verdict: UNKNOWN

input
1000000
6 3 1 2 8 5 5 4 7 6 7 10 10 1 ...

correct output
1357998

user output
(not available)

Test 10

Verdict: UNKNOWN

input
1000000
5 5 4 6 10 8 10 5 7 9 7 7 6 4 ...

correct output
1358217

user output
(not available)

Test 11

Verdict: UNKNOWN

input
1
42

correct output
42

user output
(not available)

Test 12

Verdict: UNKNOWN

input
2
58 105

correct output
58

user output
(not available)

Test 13

Verdict: UNKNOWN

input
2
5 3

correct output
3

user output
(not available)

Test 14

Verdict: UNKNOWN

input
1000000
1000 1000 1000 1000 1000 1000 ...

correct output
333334000

user output
(not available)

Test 15

Verdict: UNKNOWN

input
1000000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
333334

user output
(not available)

Test 16

Verdict: UNKNOWN

input
1
1

correct output
1

user output
(not available)

Test 17

Verdict: UNKNOWN

input
3
5 7 4

correct output
7

user output
(not available)

Test 18

Verdict: UNKNOWN

input
6
2 7 1 7 7 4

correct output
7

user output
(not available)