Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
using namespace std; int main() { int n, m; cin >> n >> m; int r, k; cin >> r >> k; r--; k--; queue
q; q.push(r); q.push(k); q.push(0); bool visited[n][m]; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { visited[i][j] = false; } } visited[r][k] = true; int di[] = {-1, 1, 0, 0}; int dj[] = {0, 0, -1, 1}; int mat[n][m]; int maksimalna_brojka = 0; while(!q.empty()) { int ci = q.front(); q.pop(); int cj = q.front(); q.pop(); int brojka = q.front(); q.pop(); mat[ci][cj] = brojka; if(brojka > maksimalna_brojka) { maksimalna_brojka = brojka; } for(int i = 0; i < 4; i++) { int ti = ci + di[i]; int tj = cj + dj[i]; if(ti >= 0 and ti < n and tj >= 0 and tj < m and !visited[ti][tj]) { visited[ti][tj] = true; q.push(ti); q.push(tj); q.push(brojka + 1); } } } int rez =0 ; for(int i =0 ; i < n; i++) { for(int j= 0; j < m; j++) { if(mat[i][j] == maksimalna_brojka) { rez++; } } } cout << maksimalna_brojka << endl; cout << rez << endl; return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)