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
#include
using namespace std; int main() { int L, W; cin >> L >> W; int treba; cin >> treba; int n; cin >> n; vector
> v(n); vector
> visited(L, vector
(W, false)); for(int i = 0; i < n; i++) { cin >> v[i].first >> v[i].second; v[i].first--; v[i].second--; visited[v[i].first][v[i].second] = true; } queue
>> q; queue
q_mesec; treba -= n; q.push(v); q_mesec.push(0); int di[] = {-1, 1, 0, 0}; int dj[] = {0, 0, -1, 1}; while(!q.empty()) { vector
> c = q.front(); q.pop(); int mesec = q_mesec.front(); q_mesec.pop(); if(treba <= 0) { cout << mesec << endl; break; } vector
> t; for(int i = 0; i < c.size(); i++) { for(int j = 0; j < 4; j++) { int ti = c[i].first + di[j]; int tj = c[i].second + dj[j]; if(ti >= 0 and ti < L and tj >= 0 and tj < W and !visited[ti][tj]) { visited[ti][tj] = true; treba--; t.push_back(make_pair(ti, tj)); } } } q.push(t); q_mesec.push(mesec + 1); } 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)