CSES - Leirikisa 6.3.2017 - Results
Submission details
Task:Karuselli
Sender:Pohjantahti
Submission time:2017-04-19 16:26:19 +0300
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED27
#2ACCEPTED31
#3ACCEPTED42
Test results
testverdicttimegroup
#1ACCEPTED0.07 s1details
#2ACCEPTED0.09 s1details
#3ACCEPTED0.08 s1details
#4ACCEPTED0.11 s1details
#5ACCEPTED0.10 s1details
#6ACCEPTED0.08 s2details
#7ACCEPTED0.21 s2details
#8ACCEPTED0.18 s2details
#9ACCEPTED0.19 s2details
#10ACCEPTED0.21 s2details
#11ACCEPTED0.09 s3details
#12ACCEPTED0.55 s3details
#13ACCEPTED0.64 s3details
#14ACCEPTED0.60 s3details
#15ACCEPTED0.71 s3details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:39:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1; i <= h.size(); ++i) {
                                 ^

Code

#include <iostream>
#include <algorithm>
#include <set>
#include <vector>

using namespace std;
typedef long long ll;
#define PB push_back

int n, k;
vector<pair<ll, int>> hs[15];
ll miel[15][100005];
set<ll> hnums; 
vector<ll> h; // relevant horses <= 196

ll dp[200][(1<<14)];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < k; ++j) {
            ll cur;
            cin >> cur;
            hs[i].PB({cur, j});
            miel[i][j] = cur;
        }
        sort(hs[i].begin(), hs[i].end());
        reverse(hs[i].begin(), hs[i].end());
        for (int j = 0; j < n; ++j) {
            hnums.insert(hs[i][j].second);
        }
    }
    for (auto a : hnums) {
        h.PB(a);
    }
    
    for (int i = 1; i <= h.size(); ++i) {
        // cur horse = i-1
        for (int j = 0; j < (1<<n); ++j) {
            dp[i][j] = dp[i-1][j];
            for (int k = 0; k < n; ++k) {
                if ((j&(1<<k)) != 0) {
                    dp[i][j] = max(dp[i][j], dp[i-1][j&(~(1<<k))]+miel[k][h[i-1]]);
                }
            }
        }
    }
    cout << dp[h.size()][(1<<n)-1] << "\n";
    return 0;
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
1 100000
557222713 738086719 759310230 ...

correct output
999997412

user output
999997412

Test 2

Group: 1

Verdict: ACCEPTED

input
2 100000
173028329 323213810 439376948 ...

correct output
1999979389

user output
1999979389

Test 3

Group: 1

Verdict: ACCEPTED

input
2 100000
499570894 150469086 335977485 ...

correct output
1999973920

user output
1999973920

Test 4

Group: 1

Verdict: ACCEPTED

input
2 100000
863032160 931625464 885185608 ...

correct output
1999939689

user output
1999939689

Test 5

Group: 1

Verdict: ACCEPTED

input
2 100000
831463088 525853809 390350738 ...

correct output
1999969705

user output
1999969705

Test 6

Group: 2

Verdict: ACCEPTED

input
1 200
344318490 251860941 939326382 ...

correct output
998010019

user output
998010019

Test 7

Group: 2

Verdict: ACCEPTED

input
14 200
43513423 154416018 137660602 1...

correct output
13918226615

user output
13918226615

Test 8

Group: 2

Verdict: ACCEPTED

input
14 200
881307544 967733810 371467276 ...

correct output
13961979091

user output
13961979091

Test 9

Group: 2

Verdict: ACCEPTED

input
14 200
522563563 350867137 498280483 ...

correct output
13912986556

user output
13912986556

Test 10

Group: 2

Verdict: ACCEPTED

input
14 200
852825364 914968833 967854069 ...

correct output
13929235436

user output
13929235436

Test 11

Group: 3

Verdict: ACCEPTED

input
1 100000
157285470 474162109 440472842 ...

correct output
999998218

user output
999998218

Test 12

Group: 3

Verdict: ACCEPTED

input
14 100000
971542960 589024445 443526352 ...

correct output
13999781843

user output
13999781843

Test 13

Group: 3

Verdict: ACCEPTED

input
14 100000
255470528 36303969 757946964 7...

correct output
13999894454

user output
13999894454

Test 14

Group: 3

Verdict: ACCEPTED

input
14 100000
18178744 935999032 93142616 43...

correct output
13999804193

user output
13999804193

Test 15

Group: 3

Verdict: ACCEPTED

input
14 100000
316827351 638928258 809826490 ...

correct output
13999909014

user output
13999909014