Task: | Maalarit |
Sender: | comp |
Submission time: | 2016-10-09 00:03:10 +0300 |
Language: | C++ |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
#2 | RUNTIME ERROR | 0 |
#3 | RUNTIME ERROR | 0 |
#4 | RUNTIME ERROR | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | WRONG ANSWER | 0.06 s | 1 | details |
#2 | RUNTIME ERROR | 0.15 s | 1 | details |
#3 | WRONG ANSWER | 0.06 s | 1 | details |
#4 | RUNTIME ERROR | 0.14 s | 1 | details |
#5 | RUNTIME ERROR | 0.14 s | 1 | details |
#6 | WRONG ANSWER | 0.05 s | 1 | details |
#7 | RUNTIME ERROR | 0.16 s | 2 | details |
#8 | RUNTIME ERROR | 0.13 s | 2 | details |
#9 | RUNTIME ERROR | 0.14 s | 2 | details |
#10 | RUNTIME ERROR | 0.15 s | 2 | details |
#11 | RUNTIME ERROR | 0.14 s | 2 | details |
#12 | WRONG ANSWER | 0.05 s | 2 | details |
#13 | RUNTIME ERROR | 0.14 s | 3 | details |
#14 | WRONG ANSWER | 0.06 s | 3 | details |
#15 | RUNTIME ERROR | 0.15 s | 3 | details |
#16 | WRONG ANSWER | 0.05 s | 3 | details |
#17 | RUNTIME ERROR | 0.15 s | 3 | details |
#18 | WRONG ANSWER | 0.05 s | 3 | details |
#19 | RUNTIME ERROR | 0.31 s | 4 | details |
#20 | RUNTIME ERROR | 0.31 s | 4 | details |
#21 | RUNTIME ERROR | 0.29 s | 4 | details |
#22 | RUNTIME ERROR | 0.30 s | 4 | details |
#23 | RUNTIME ERROR | 0.29 s | 4 | details |
#24 | TIME LIMIT EXCEEDED | -- | 4 | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:222:27: warning: 'total_cost' may be used uninitialized in this function [-Wmaybe-uninitialized] total_cost += cost; ^
Code
#include <iostream> #include <vector> #include <map> int number_of_boards; std::map<int, int> board_painters; // board:painter=1,2,3 int costs[3] = {0, 0, 0}; std::map<int, int> board_set_bottom; std::map<int, int> board_set_top; int painters_for_two(std::pair<int, int> board_one, std::pair<int, int> board_two) { int board_one_location = board_one.first; int board_two_location = board_two.first; int board_one_height = board_one.second; int board_two_height = board_two.second; if (board_one.second >= board_two.second) { board_painters.insert(std::pair<int, int>(board_one_location, 2)); board_painters.insert(std::pair<int, int>(board_two_location, 1)); if (board_one_height > costs[1]) { costs[1] = board_one_height; } if (board_two_height > costs[0]) { costs[0] = board_two_height; } } else { board_painters.insert(std::pair<int, int>(board_one_location, 1)); board_painters.insert(std::pair<int, int>(board_two_location, 2)); if (board_one_height > costs[0]) { costs[0] = board_one_height; } if (board_two_height > costs[1]) { costs[1] = board_two_height; } } return 0; } int find_painters(std::map<int, int> boards, bool is_bottom) { std::pair<int, int> tallestBoard = std::pair<int, int>(boards.rbegin()->first, boards.rbegin()->second); for(auto board: boards) { if (board.second > tallestBoard.second) { tallestBoard = board; } } int tallestLocation = tallestBoard.first; int tallestHeight = tallestBoard.second; if (tallestLocation == boards.begin()->first && is_bottom == false) { std::map<int, int> boards_subset = boards; boards_subset.erase(boards.begin()->first); tallestBoard = std::pair<int, int>(boards_subset.rbegin()->first, boards_subset.rbegin()->second); for(auto board: boards_subset) { if (board.second > tallestBoard.second) { tallestBoard = board; } } tallestLocation = tallestBoard.first; tallestHeight = tallestBoard.second; } else if (tallestLocation == boards.rbegin()->first && is_bottom == true) { std::map<int, int> boards_subset = boards; boards_subset.erase(boards.rbegin()->first); tallestBoard = std::pair<int, int>(boards_subset.rbegin()->first, boards_subset.rbegin()->second); for(auto board: boards_subset) { if (board.second > tallestBoard.second) { tallestBoard = board; } } tallestLocation = tallestBoard.first; tallestHeight = tallestBoard.second; } board_painters.insert(std::pair<int, int>(tallestLocation, 3)); if (tallestHeight > costs[2]) { costs[2] = tallestHeight; } board_set_bottom.clear(); board_set_top.clear(); for(auto board: boards) { if (board.first < tallestLocation) { board_set_bottom.insert(std::pair<int, int>(board.first, board.second)); } else if (board.first > tallestLocation) { board_set_top.insert(std::pair<int, int>(board.first, board.second)); } } if (board_set_top.size() > 1 && board_set_top.rbegin()->first == number_of_boards) { std::map<int, int> bottom_set_copy = board_set_bottom; find_painters(board_set_top, false); board_set_top.clear(); board_set_bottom = bottom_set_copy; } else if (board_set_bottom.size() > 1 && board_set_bottom.begin()->first == 1) { std::map<int, int> top_set_copy = board_set_top; find_painters(board_set_bottom, true); board_set_bottom.clear(); board_set_top = top_set_copy; } int bottom_size = board_set_bottom.size(); int top_size = board_set_bottom.size(); if (bottom_size > 2) { find_painters(board_set_bottom, true); } else if (bottom_size == 2) { std::pair<int, int> board_one = std::pair<int, int>(board_set_bottom.begin()->first, board_set_bottom.begin()->second); std::pair<int, int> board_two = std::pair<int, int>(board_set_bottom.rbegin()->first, board_set_bottom.rbegin()->second); painters_for_two(board_one, board_two); } else if (bottom_size == 1 && board_set_bottom.empty() == false) { std::pair<int, int> board = std::pair<int, int>(board_set_bottom.begin()->first, board_set_bottom.begin()->second); board_painters.insert(std::pair<int, int>(board.first, 2)); if (board.second > costs[1]) { costs[1] = board.second; } } if (top_size > 2) { find_painters(board_set_top, false); } else if (top_size == 2) { std::pair<int, int> board_one = std::pair<int, int>(board_set_top.begin()->first, board_set_top.begin()->second); std::pair<int, int> board_two = std::pair<int, int>(board_set_top.rbegin()->first, board_set_top.rbegin()->second); painters_for_two(board_one, board_two); } else if (top_size == 1 && board_set_top.empty() == false) { std::pair<int, int> board = std::pair<int, int>(board_set_top.begin()->first, board_set_top.begin()->second); board_painters.insert(std::pair<int, int>(board.first, 2)); if (board.second > costs[1]) { costs[1] = board.second; } } return 0; } int find_first_painter(std::map<int, int> boards) { if (boards.size() == 1) { std::pair<int, int> board = std::pair<int, int>(boards.begin()->first, boards.begin()->second); costs[0] = board.second; board_painters.insert(std::pair<int, int>(board.first, 1)); return 0; } else if (boards.size() == 2) { std::pair<int, int> board_one = std::pair<int, int>(boards.begin()->first, boards.begin()->second); std::pair<int, int> board_two = std::pair<int, int>(boards.rbegin()->first, boards.rbegin()->second); costs[0] = board_one.second; costs[1] = board_two.second; board_painters.insert(std::pair<int, int>(board_one.first, 1)); board_painters.insert(std::pair<int, int>(board_two.first, 2)); return 0; } std::pair<int, int> tallestBoard = std::pair<int, int>(boards.rbegin()->first, boards.rbegin()->second); for(auto board: boards) { if (board.second > tallestBoard.second) { tallestBoard = board; } } int tallestLocation = tallestBoard.first; int tallestHeight = tallestBoard.second; board_painters.insert(std::pair<int, int>(tallestLocation, 3)); costs[2] = tallestHeight; for(auto board: boards) { if (board.first < tallestLocation) { board_set_bottom.insert(std::pair<int, int>(board.first, board.second)); } else if (board.first > tallestLocation) { board_set_top.insert(std::pair<int, int>(board.first, board.second)); } } std::vector<std::map<int, int>> board_sets; board_sets.push_back(board_set_bottom); board_sets.push_back(board_set_top); for(auto board_set: board_sets) { int set_size = board_set.size(); if (set_size == 0) { continue; } if (set_size > 2) { if (board_set == board_set_bottom) { find_painters(board_set, true); } else { find_painters(board_set, false); } } else if (board_set.rbegin()->first == number_of_boards && board_set == board_set_top && set_size != 1) { find_painters(board_set, false); } else if (board_set.begin()->first == 1 && board_set == board_set_bottom && set_size != 1) { find_painters(board_set, true); } else if (set_size == 1) { std::pair<int, int> board = *(board_set.rbegin()); board_painters.insert(std::pair<int, int>(board.first, 2)); if (board.second > costs[1]) { costs[1] = board.second; } } } return 0; } int main() { std::cin >> number_of_boards; std::map<int, int> boards; int x; for(int p = 1; p <= number_of_boards; ++p) { std::cin >> x; boards.insert(std::pair<int, int>(p, x)); // location, height } find_first_painter(boards); int total_cost; int number_of_painters = 0; for(auto cost: costs) { total_cost += cost; if (cost != 0) { number_of_painters += 1; } } int lowest_painter = 3; for(auto set: board_painters) { if (set.second < lowest_painter) { lowest_painter = set.second; } } if (lowest_painter != 1) { for(auto set: board_painters) { std::pair<int, int> new_set = std::pair<int, int>(set.first, set.second - lowest_painter + 1); board_painters.erase(set.first); board_painters.insert(new_set); } } if (number_of_painters == 3) { int first_digit = board_painters.at(1); int second_digit = board_painters.at(2); for(auto set: board_painters) { int value = set.second; std::pair<int, int> new_set; if (value == first_digit) { new_set = std::pair<int, int>(set.first, 1); } else if (value == second_digit) { new_set = std::pair<int, int>(set.first, 2); } else { new_set = std::pair<int, int>(set.first, 3); } board_painters.erase(set.first); board_painters.insert(new_set); } } else if (number_of_painters == 2) { if (board_painters.at(1) != 1) { for(auto set: board_painters) { std::pair<int, int> new_set; if (set.second == 1) { new_set = std::pair<int, int>(set.first, 2); } else { new_set = std::pair<int, int>(set.first, 1); } board_painters.erase(set.first); board_painters.insert(new_set); } } } std::cout << total_cost << " " << number_of_painters << "\n"; for(auto set: board_painters) { std::cout << set.second << " "; } return 0; }
Test details
Test 1
Group: 1
Verdict: WRONG ANSWER
input |
---|
10 22 54 3 91 69 90 40 29 83 71 |
correct output |
---|
174 3 2 1 2 1 2 1 2 1 2 1 |
user output |
---|
233 3 1 2 1 2 1 2 1 3 2 1 |
Test 2
Group: 1
Verdict: RUNTIME ERROR
input |
---|
10 49 3 96 38 90 18 92 74 83 1 |
correct output |
---|
170 3 1 2 1 2 1 2 1 2 1 2 |
user output |
---|
(empty) |
Test 3
Group: 1
Verdict: WRONG ANSWER
input |
---|
10 46 3 41 30 16 17 12 93 80 81 |
correct output |
---|
173 3 2 1 2 1 2 1 2 1 2 1 |
user output |
---|
93 1 1 1 |
Test 4
Group: 1
Verdict: RUNTIME ERROR
input |
---|
10 46 8 95 85 82 73 82 92 53 90 |
correct output |
---|
187 3 1 2 1 2 1 2 1 2 1 2 |
user output |
---|
(empty) |
Test 5
Group: 1
Verdict: RUNTIME ERROR
input |
---|
10 41 18 61 59 40 96 5 2 74 38 |
correct output |
---|
159 3 2 1 2 1 2 1 2 3 1 2 |
user output |
---|
(empty) |
Error:
terminate called after throwing an instance of 'std::out_of_range' what(): map::at
Test 6
Group: 1
Verdict: WRONG ANSWER
input |
---|
10 1 1 1 1 1 1 1 1 1 1 |
correct output |
---|
2 3 2 1 2 1 2 1 2 1 2 1 |
user output |
---|
2 2 1 2 1 2 2 2 2 |
Test 7
Group: 2
Verdict: RUNTIME ERROR
input |
---|
100 1 39 94 5 24 84 84 10 78 61 38... |
correct output |
---|
193 3 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 ... |
user output |
---|
(empty) |
Test 8
Group: 2
Verdict: RUNTIME ERROR
input |
---|
100 31 73 18 88 49 28 66 5 32 48 9... |
correct output |
---|
199 3 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 ... |
user output |
---|
(empty) |
Test 9
Group: 2
Verdict: RUNTIME ERROR
input |
---|
100 45 56 36 60 31 10 23 79 29 17 ... |
correct output |
---|
198 3 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 ... |
user output |
---|
(empty) |
Test 10
Group: 2
Verdict: RUNTIME ERROR
input |
---|
100 1 77 70 62 21 68 40 54 90 62 1... |
correct output |
---|
194 3 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 ... |
user output |
---|
(empty) |
Test 11
Group: 2
Verdict: RUNTIME ERROR
input |
---|
100 4 47 41 81 56 64 12 10 20 100 ... |
correct output |
---|
189 3 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 ... |
user output |
---|
(empty) |
Test 12
Group: 2
Verdict: WRONG ANSWER
input |
---|
10 1 1 1 1 1 1 1 1 1 1 |
correct output |
---|
2 3 2 1 2 1 2 1 2 1 2 1 |
user output |
---|
2 2 1 2 1 2 2 2 2 |
Test 13
Group: 3
Verdict: RUNTIME ERROR
input |
---|
100 256160448 813097800 167146270 ... |
correct output |
---|
1929869257 3 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 ... |
user output |
---|
(empty) |
Test 14
Group: 3
Verdict: WRONG ANSWER
input |
---|
100 520002672 3542567 24668528 959... |
correct output |
---|
1946957555 3 1 2 3 1 2 1 2 1 2 1 2 1 2 1 2 ... |
user output |
---|
1544138146 2 1 1 1 1 1 2 1 2 |
Test 15
Group: 3
Verdict: RUNTIME ERROR
input |
---|
100 483158423 780224665 844754665 ... |
correct output |
---|
1959373560 3 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 ... |
user output |
---|
(empty) |
Test 16
Group: 3
Verdict: WRONG ANSWER
input |
---|
100 969647264 128558017 889036329 ... |
correct output |
---|
1997942264 3 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 ... |
user output |
---|
1288336378 2 1 1 1 1 1 1 2 1 2 1 1 2 1 |
Test 17
Group: 3
Verdict: RUNTIME ERROR
input |
---|
100 745018527 400495893 635468795 ... |
correct output |
---|
1961391143 3 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 ... |
user output |
---|
(empty) |
Test 18
Group: 3
Verdict: WRONG ANSWER
input |
---|
10 1 1 1 1 1 1 1 1 1 1 |
correct output |
---|
2 3 2 1 2 1 2 1 2 1 2 1 |
user output |
---|
2 2 1 2 1 2 2 2 2 |
Test 19
Group: 4
Verdict: RUNTIME ERROR
input |
---|
100000 197349274 775463806 263930657 ... |
correct output |
---|
1999942635 3 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 ... |
user output |
---|
(empty) |
Test 20
Group: 4
Verdict: RUNTIME ERROR
input |
---|
100000 102296405 34648120 320393597 9... |
correct output |
---|
1999930943 3 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 ... |
user output |
---|
(empty) |
Test 21
Group: 4
Verdict: RUNTIME ERROR
input |
---|
100000 781254921 418252056 502363453 ... |
correct output |
---|
1999987794 3 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 ... |
user output |
---|
(empty) |
Test 22
Group: 4
Verdict: RUNTIME ERROR
input |
---|
100000 849784881 230439009 455097426 ... |
correct output |
---|
1999979439 3 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 ... |
user output |
---|
(empty) |
Test 23
Group: 4
Verdict: RUNTIME ERROR
input |
---|
100000 851456132 13422224 537539701 4... |
correct output |
---|
1999948226 3 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 ... |
user output |
---|
(empty) |
Test 24
Group: 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
correct output |
---|
2 3 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 ... |
user output |
---|
(empty) |