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; typedef long long ll; const int maxn = 5000; vector
graph[maxn]; int main() { int n, m; cin >> n >> m; char c[n][m]; int mat[n][m]; int idx = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { cin >> c[i][j]; mat[i][j] = idx; idx++; } } int di[] = {-1, 1, 0, 0}; int dj[] = {0, 0, -1, 1}; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { 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 c[i][j] == c[ti][tj]) { graph[mat[i][j]].push_back(mat[ti][tj]); graph[mat[ti][tj]].push_back(mat[i][j]); } } } } 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)