Submission #407068

#TimeUsernameProblemLanguageResultExecution timeMemory
407068Nodir_BobievRobots (APIO13_robots)C++17
0 / 100
1 ms452 KiB
/* In the name of Allah */ # include <bits/stdc++.h> using namespace std; const int inf = 1000000; int n, w, h, dist[10][600][600]; int directions[4][2] = { {0, -1}, {-1, 0}, {0, 1}, {1, 0} }; string grid[600]; bool ok( int x, int y ){ return( 0 <= x && x < h && 0 <= y && y < w && grid[x][y] != 'x'); } void bfs( int x, int y, int id ){ for( int i = 0; i < h; i ++ ) for( int j = 0; j < w; j ++ ) dist[id][i][j] = inf; dist[id][x][y] = 0; queue < pair < int, int > > q; q.push({x,y}); while( !q.empty() ){ auto fr = q.front(); q.pop(); x = fr.first; y = fr.second; for( auto dir: directions ){ int xx = x, yy = y; while( ok(xx+dir[0], yy+dir[1]) ){ xx += dir[0]; yy += dir[1]; } if( dist[id][xx][yy] == inf ){ dist[id][xx][yy] = dist[id][x][y] + 1; q.push({xx,yy}); } } } } int main(){ cin >> n >> w >> h; for( int i = 0; i < h; i ++ ){ cin >> grid[i]; } for( int i = 0; i < h; i ++ ){ for( int j = 0; j < w; j ++ ){ if( '1' <= grid[i][j] && grid[i][j] <= '9' ) bfs(i, j, grid[i][j] - '0'); } } int ans = inf; for( int i = 0; i < h; i ++ ){ for( int j = 0; j < w; j ++ ){ ans = min( ans, dist[1][i][j] + dist[2][i][j] ); } } cout << ans; } /* 4 10 5 1......... AA...x4... ..A..x.... 2....x.... ..C.3.A... */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...