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
#include
using namespace std; const int maxn = 500; const int di[] = {-1, 1, 0, 0}; const int dj[] = {0, 0, -1, 1}; int n, m; char mat[maxn][maxn]; bool visited[maxn][maxn]; int wolves, sheep; void dfs(int i, int j) { // cout << i << " " << j << endl; visited[i][j] = true; if(mat[i][j] == 'v') { wolves++; } if(mat[i][j] == 'o') { sheep++; } for(int k = 0; k < 4; k++) { int ti = i + di[k]; int tj = j + dj[k]; if(ti >= 0 and ti < n and tj >= 0 and tj < m and !visited[ti][tj] and mat[ti][tj] != '#') { dfs(ti, tj); } } } int main() { ios_base::sync_with_stdio(false); cin >> n >> m; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { cin >> mat[i][j]; visited[i][j] = false; } } int res_sheep = 0, res_wolves = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(mat[i][j] != '#' and !visited[i][j]) { wolves = 0; sheep = 0; dfs(i, j); if(sheep > wolves) { res_sheep += sheep; } else { res_wolves += wolves; } } } } cout << res_sheep << " " << res_wolves << endl; return 0; } /* 6 6 1 2 2 3 2 5 3 5 3 4 5 6 **/
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)