Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
Python
SQL
Shell
Markdown
YAML
JSON
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
TypeScript
Perl
Lua
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#define lvl first #define row second.first #define col second.second using namespace std; int h, n, m, d[51][51][51]; char table[51][51][51]; pair
> s, f; pair
> dir[5] = {{0, {-1, 0}}, {0, {0, +1}}, {0, {+1, 0}}, {0, {0, -1}}, {+1, {0, 0}}}; bool used[51][51][51]; queue
>> q; bool check(int lv, int r, int c) { return (1 <= lv && lv <= h && 1 <= r && r <= n && 1 <= c && c <= m && table[lv][r][c] != 'o'); } int main() { cin >> h >> n >> m; for (int k = 1; k <= h; ++k) { for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { cin >> table[k][i][j]; if (table[k][i][j] == '1') { s = {k, {i, j}}; d[k][i][j] = 0; used[k][i][j] = true; q.push({k, {i, j}}); } else if (table[k][i][j] == '2') { f = {k, {i, j}}; } } } } while (!q.empty()) { auto v = q.front(); q.pop(); for (int i = 0; i < 5; ++i) { int k = v.lvl + dir[i].lvl; int x = v.row + dir[i].row; int y = v.col + dir[i].col; if (check(k, x, y) && !used[k][x][y]) { used[k][x][y] = true; d[k][x][y] = d[v.lvl][v.row][v.col] + 1; q.push({k, {x, y}}); } } } cout << d[f.lvl][f.row][f.col] * 5; return 0; }
Mark as private
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year