Task: | Karuselli |
Sender: | mangolassi |
Submission time: | 2017-03-06 15:52:46 +0200 |
Language: | C++ |
Status: | READY |
Result: | 27 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 27 |
#2 | TIME LIMIT EXCEEDED | 0 |
#3 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.07 s | 1 | details |
#2 | ACCEPTED | 0.10 s | 1 | details |
#3 | ACCEPTED | 0.10 s | 1 | details |
#4 | ACCEPTED | 0.11 s | 1 | details |
#5 | ACCEPTED | 0.09 s | 1 | details |
#6 | ACCEPTED | 0.04 s | 2 | details |
#7 | TIME LIMIT EXCEEDED | -- | 2 | details |
#8 | TIME LIMIT EXCEEDED | -- | 2 | details |
#9 | TIME LIMIT EXCEEDED | -- | 2 | details |
#10 | TIME LIMIT EXCEEDED | -- | 2 | details |
#11 | ACCEPTED | 0.06 s | 3 | details |
#12 | TIME LIMIT EXCEEDED | -- | 3 | details |
#13 | TIME LIMIT EXCEEDED | -- | 3 | details |
#14 | TIME LIMIT EXCEEDED | -- | 3 | details |
#15 | TIME LIMIT EXCEEDED | -- | 3 | details |
Code
#include <iostream> #include <vector> #include <algorithm> #include <utility> int n; int k; const int N = 14; const int K = 1e5; std::pair<int, int> want[N][N]; bool used[K]; int done[N]; long long doit(int left) { long long max = 0; for (int i = 0; i < left; ++i) { int guy = done[i]; done[i] = done[left - 1]; int horse = 0; for (;; ++horse) { if (! used[want[guy][horse].second]) { break; } } used[want[guy][horse].second] = true; long long offer = doit(left - 1) + want[guy][horse].first; if (offer > max) { max = offer; } done[left - 1] = done[i]; done[i] = guy; used[want[guy][horse].second] = false; } return max; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cin >> n >> k; for (int i = 0; i < n; ++i) { std::vector<std::pair<int, int> > sort; for (int j = 0; j < k; ++j) { int v; std::cin >> v; sort.push_back(std::make_pair(-v, j)); } std::sort(sort.begin(), sort.end()); for (int j = 0; j < n; ++j) { want[i][j] = std::make_pair(-sort[j].first, sort[j].second); } } for (int i = 0; i < n; ++i) { done[i] = i; } std::cout << doit(n) << "\n"; }
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: TIME LIMIT EXCEEDED
input |
---|
14 200 43513423 154416018 137660602 1... |
correct output |
---|
13918226615 |
user output |
---|
(empty) |
Test 8
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
14 200 881307544 967733810 371467276 ... |
correct output |
---|
13961979091 |
user output |
---|
(empty) |
Test 9
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
14 200 522563563 350867137 498280483 ... |
correct output |
---|
13912986556 |
user output |
---|
(empty) |
Test 10
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
14 200 852825364 914968833 967854069 ... |
correct output |
---|
13929235436 |
user output |
---|
(empty) |
Test 11
Group: 3
Verdict: ACCEPTED
input |
---|
1 100000 157285470 474162109 440472842 ... |
correct output |
---|
999998218 |
user output |
---|
999998218 |
Test 12
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
14 100000 971542960 589024445 443526352 ... |
correct output |
---|
13999781843 |
user output |
---|
(empty) |
Test 13
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
14 100000 255470528 36303969 757946964 7... |
correct output |
---|
13999894454 |
user output |
---|
(empty) |
Test 14
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
14 100000 18178744 935999032 93142616 43... |
correct output |
---|
13999804193 |
user output |
---|
(empty) |
Test 15
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
14 100000 316827351 638928258 809826490 ... |
correct output |
---|
13999909014 |
user output |
---|
(empty) |