| Task: | Mission |
| Sender: | OOliOO_slayer |
| Submission time: | 2015-10-07 17:59:36 +0300 |
| Language: | C++ |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.06 s | details |
| #2 | WRONG ANSWER | 0.06 s | details |
| #3 | WRONG ANSWER | 0.05 s | details |
| #4 | WRONG ANSWER | 0.05 s | details |
| #5 | WRONG ANSWER | 0.05 s | details |
| #6 | WRONG ANSWER | 0.05 s | details |
| #7 | WRONG ANSWER | 0.05 s | details |
| #8 | WRONG ANSWER | 0.05 s | details |
| #9 | WRONG ANSWER | 0.05 s | details |
| #10 | ACCEPTED | 0.06 s | details |
| #11 | WRONG ANSWER | 0.05 s | details |
| #12 | WRONG ANSWER | 0.05 s | details |
| #13 | WRONG ANSWER | 0.05 s | details |
| #14 | WRONG ANSWER | 0.05 s | details |
| #15 | WRONG ANSWER | 0.05 s | details |
| #16 | WRONG ANSWER | 0.05 s | details |
| #17 | ACCEPTED | 0.06 s | details |
| #18 | WRONG ANSWER | 0.05 s | details |
| #19 | WRONG ANSWER | 0.06 s | details |
| #20 | WRONG ANSWER | 0.05 s | details |
| #21 | WRONG ANSWER | 0.05 s | details |
| #22 | WRONG ANSWER | 0.05 s | details |
| #23 | WRONG ANSWER | 0.06 s | details |
| #24 | WRONG ANSWER | 0.05 s | details |
| #25 | WRONG ANSWER | 0.06 s | details |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:77:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < line.size(); j++){
^Code
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <utility>
#include <set>
#include <deque>
typedef long long LL;
using namespace std;
LL n,m,k;
class Node{
public:
int r,c,dist;
Node(int r, int c, int dist){
this->r = r;
this->c = c;
this->dist = dist;
}
};
bool free(int r, int c, vector<vector<char> >& grid){
return grid[r][c] != '#';
}
void bfs(int r, int c, int start, vector<vector<char> >& grid, vector<vector<int> >& D){
deque<Node> Q;
vector<vector<char> > visited(n, vector<char>(m));
Q.push_back(Node(r,c,0));
while(!Q.empty()){
auto v = Q.front(); Q.pop_front();
r = v.r;
c = v.c;
if(visited[r][c]) continue;
visited.at(r).at(c) = 1;
char symbol = grid[r][c];
if(symbol >= '0' && symbol <= '9'){
D[start][symbol-'0'] = v.dist;
D[symbol-'0'][start] = v.dist;
}
if(r > 0 && free(r-1, c, grid)){
Node u(r-1,c,v.dist+1);
Q.push_back(u);
}
if(r < n-1 && free(r+1, c, grid)) {
Node u(r+1,c,v.dist+1);
Q.push_back(u);
}
if(c > 0 && free(r, c-1, grid)){
Node u(r,c-1,v.dist+1);
Q.push_back(u);
}
if(c < m-1 && free(r, c+1, grid)){
Node u(r,c+1,v.dist+1);
Q.push_back(u);
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
vector<vector<char> > grid(n, vector<char>(m));
map<int,pair<int,int> > special;
int coin_counter = 1;
for(int i = 0; i < n; i++){
string line; cin >> line;
for(int j = 0; j < line.size(); j++){
grid[i][j] = line[j];
if(line[j] == '*'){
grid[i][j] = '0' + coin_counter;
special[coin_counter] = {i,j};
coin_counter++;
}
else if(line[j] == 'A'){
special[0] = {i,j};
grid[i][j] = '0';
}
else if(line[j] == 'B'){
special[k+1] = {i,j};
grid[i][j] = '0' + k + 1;
}
}
//for(auto c : grid[i]) cout << c; cout << endl;
}
vector<vector<int> > D(k+2, vector<int>(k+2));
for(auto keyvalue : special){
int id = keyvalue.first;
int r = keyvalue.second.first;
int c = keyvalue.second.second;
bfs(r, c, id, grid, D);
}
if(k == 0){
cout << D[0][k+1] << endl;
return 0;
}
for(int i = 0; i < k+2; i++){
for(int j = 0; j < k+2; j++){
cout << D[i][j] << " ";
}
cout << endl;
}
vector<int> permutation;
for(int i = 1; i <= k; i++){
permutation.push_back(i);
}
LL ans = 1e9;
do {
LL score = 0;
for(int i = 0; i < k-1; i++){
score += D[permutation[i]][permutation[i+1]];
}
score += D[0][permutation[0]];
score += D[permutation.back()][k+1];
ans = min(ans,score);
} while (next_permutation(permutation.begin(), permutation.end()) );
cout << ans << endl;
}Test details
Test 1
Verdict: WRONG ANSWER
| input |
|---|
| 84 87 2 ##############################... |
| correct output |
|---|
| 104 |
| user output |
|---|
| 0 29 30 12 29 0 57 17 30 57 0 40 12 17 40 0 104 |
Test 2
Verdict: WRONG ANSWER
| input |
|---|
| 100 100 8 ##############################... |
| correct output |
|---|
| 264 |
| user output |
|---|
| 0 88 63 70 61 47 33 62 34 28 88 0 29 18 45 41 65 40 118 60 63 29 0 17 20 24 40 41 93 35 70 18 17 0 27 23 47 28 100 42 61 45 20 27 0 22 38 39 91 33 ... |
Test 3
Verdict: WRONG ANSWER
| input |
|---|
| 26 51 1 ##############################... |
| correct output |
|---|
| 48 |
| user output |
|---|
| 0 27 6 27 0 21 6 21 0 48 |
Test 4
Verdict: WRONG ANSWER
| input |
|---|
| 100 100 8 ##############################... |
| correct output |
|---|
| 145 |
| user output |
|---|
| 0 9 17 35 21 26 47 52 55 57 9 0 8 26 16 23 38 47 50 52 17 8 0 18 22 29 30 53 56 50 35 26 18 0 18 25 16 49 52 44 21 16 22 18 0 7 28 31 34 38 ... |
Test 5
Verdict: WRONG ANSWER
| input |
|---|
| 68 50 7 ##############################... |
| correct output |
|---|
| 88 |
| user output |
|---|
| 0 22 12 18 7 6 10 21 6 22 0 14 6 23 28 30 43 16 12 14 0 12 17 18 20 33 6 18 6 12 0 19 24 26 39 12 7 23 17 19 0 5 7 20 11 ... |
Test 6
Verdict: WRONG ANSWER
| input |
|---|
| 100 100 8 ##############################... |
| correct output |
|---|
| 187 |
| user output |
|---|
| 0 26 23 19 21 29 40 42 40 15 26 0 39 35 47 47 42 54 62 25 23 39 0 42 34 52 63 61 59 26 19 35 42 0 12 12 21 23 29 30 21 47 34 12 0 18 29 27 25 36 ... |
Test 7
Verdict: WRONG ANSWER
| input |
|---|
| 61 79 6 ##############################... |
| correct output |
|---|
| 149 |
| user output |
|---|
| 0 25 36 29 14 45 27 31 25 0 21 36 33 60 46 6 36 21 0 17 26 41 47 25 29 36 17 0 19 24 40 42 14 33 26 19 0 33 21 39 ... |
Test 8
Verdict: WRONG ANSWER
| input |
|---|
| 100 100 8 ##############################... |
| correct output |
|---|
| 232 |
| user output |
|---|
| 0 36 21 30 30 18 73 38 33 90 36 0 43 28 30 24 73 58 53 90 21 43 0 47 49 37 92 57 52 109 30 28 47 0 2 18 45 52 47 62 30 30 49 2 0 16 43 50 45 60 ... |
Test 9
Verdict: WRONG ANSWER
| input |
|---|
| 94 27 6 ########################### ########################### ########################### #############.############# ... |
| correct output |
|---|
| 82 |
| user output |
|---|
| 0 20 6 4 9 8 23 6 20 0 18 20 29 26 43 26 6 18 0 2 11 12 25 10 4 20 2 0 9 10 23 8 9 29 11 9 0 9 14 7 ... |
Test 10
Verdict: ACCEPTED
| input |
|---|
| 100 100 0 ##############################... |
| correct output |
|---|
| 30 |
| user output |
|---|
| 30 |
Test 11
Verdict: WRONG ANSWER
| input |
|---|
| 65 100 6 ######.#######################... |
| correct output |
|---|
| 233 |
| user output |
|---|
| 0 28 43 35 46 69 19 9 28 0 49 21 42 77 41 27 43 49 0 56 69 98 28 46 35 21 56 0 21 56 48 26 46 42 69 21 0 35 59 37 ... |
Test 12
Verdict: WRONG ANSWER
| input |
|---|
| 100 100 8 ##############################... |
| correct output |
|---|
| 209 |
| user output |
|---|
| 0 65 47 39 47 37 22 40 28 41 65 0 18 52 98 90 53 103 93 106... |
Test 13
Verdict: WRONG ANSWER
| input |
|---|
| 75 18 3 ################## ################## ################## ################## ... |
| correct output |
|---|
| 72 |
| user output |
|---|
| 0 13 1 17 34 13 0 12 26 27 1 12 0 18 33 17 26 18 0 51 34 27 33 51 0 ... |
Test 14
Verdict: WRONG ANSWER
| input |
|---|
| 100 100 8 ##############################... |
| correct output |
|---|
| 196 |
| user output |
|---|
| 0 57 29 14 23 27 31 33 30 16 57 0 40 71 80 84 88 90 75 73 29 40 0 39 44 48 52 56 59 45 14 71 39 0 9 13 17 19 24 8 23 80 44 9 0 4 8 14 33 17 ... |
Test 15
Verdict: WRONG ANSWER
| input |
|---|
| 62 4 3 ###. #### #### #### ... |
| correct output |
|---|
| 44 |
| user output |
|---|
| 0 16 1 9 6 16 0 17 25 10 1 17 0 8 7 9 25 8 0 15 6 10 7 15 0 ... |
Test 16
Verdict: WRONG ANSWER
| input |
|---|
| 100 100 8 ##############################... |
| correct output |
|---|
| 231 |
| user output |
|---|
| 0 73 78 51 50 57 60 50 40 25 73 0 57 28 29 36 41 51 77 66 78 57 0 37 62 73 78 88 44 53 51 28 37 0 33 44 49 59 49 38 50 29 62 33 0 11 16 26 54 43 ... |
Test 17
Verdict: ACCEPTED
| input |
|---|
| 15 4 0 ###. .### #### #.#. ... |
| correct output |
|---|
| 4 |
| user output |
|---|
| 4 |
Test 18
Verdict: WRONG ANSWER
| input |
|---|
| 100 100 8 ##############################... |
| correct output |
|---|
| 300 |
| user output |
|---|
| 0 32 31 41 85 82 54 66 100 42 32 0 21 41 53 50 76 88 122 20 31 21 0 20 54 51 55 67 101 11 41 41 20 0 44 41 35 47 81 21 85 53 54 44 0 11 57 69 103 43 ... |
Test 19
Verdict: WRONG ANSWER
| input |
|---|
| 86 15 2 .########....## #########...... #########...... #########...... ... |
| correct output |
|---|
| 88 |
| user output |
|---|
| 0 34 44 70 34 0 20 44 44 20 0 34 70 44 34 0 88 |
Test 20
Verdict: WRONG ANSWER
| input |
|---|
| 100 100 8 ##############################... |
| correct output |
|---|
| 288 |
| user output |
|---|
| 0 74 51 58 51 19 50 14 93 18 74 0 23 16 49 55 64 88 121 56 51 23 0 13 52 32 67 65 124 33 58 16 13 0 39 39 54 72 111 40 51 49 52 39 0 34 15 65 72 35 ... |
Test 21
Verdict: WRONG ANSWER
| input |
|---|
| 51 90 3 ................................. |
| correct output |
|---|
| 103 |
| user output |
|---|
| 0 45 28 54 31 45 0 17 11 48 28 17 0 26 31 54 11 26 0 47 31 48 31 47 0 ... |
Test 22
Verdict: WRONG ANSWER
| input |
|---|
| 100 100 8 ................................. |
| correct output |
|---|
| 352 |
| user output |
|---|
| 0 15 27 12 15 71 86 68 151 98 15 0 32 21 30 76 91 73 156 87 27 32 0 33 42 44 59 59 124 71 12 21 33 0 9 59 74 56 139 104 15 30 42 9 0 64 79 61 144 113 ... |
Test 23
Verdict: WRONG ANSWER
| input |
|---|
| 22 91 4 ................................. |
| correct output |
|---|
| 128 |
| user output |
|---|
| 0 9 26 40 49 8 9 0 17 47 56 1 26 17 0 52 61 18 40 47 52 0 9 48 49 56 61 9 0 57 ... |
Test 24
Verdict: WRONG ANSWER
| input |
|---|
| 100 100 8 ................................. |
| correct output |
|---|
| 317 |
| user output |
|---|
| 0 44 24 58 22 69 76 107 64 39 44 0 58 94 60 113 120 151 108 ... |
Test 25
Verdict: WRONG ANSWER
| input |
|---|
| 49 42 6 ................................. |
| correct output |
|---|
| 175 |
| user output |
|---|
| 0 36 30 17 21 34 40 13 36 0 36 19 33 46 76 41 30 36 0 45 51 64 52 43 17 19 45 0 14 27 57 22 21 33 51 14 0 13 43 8 ... |
