# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
530618 | kevin | Dango Maker (JOI18_dango_maker) | C++17 | 124 ms | 211984 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define nl cout<<"\n"
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define ca(v) for(auto i:v) cout<<i<<" ";
const int MOD = 1e9 + 7;
int onv[3001][3001];
int onh[3001][3001];
list<int> adj[3001*3001];
bool vis[3001*3001];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
if (fopen("input.in", "r")) freopen("input.in", "r", stdin);
int n, m; cin>>n>>m;
char grid[n][m];
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
cin>>grid[i][j];
}
}
int cnt = 0;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(grid[i][j] == 'R' && j+2 < m && grid[i][j+1] == 'G' && grid[i][j+2] == 'W') onh[i][j] = ++cnt;
}
}
for(int j=0; j<m; j++){
for(int i=0; i<n; i++){
if(grid[i][j] == 'R' && i+2 < n && grid[i+1][j] == 'G' && grid[i+2][j] == 'W') onv[i][j] = ++cnt;
}
}
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(onh[i][j]){
for(int k=0; k<3; k++){
if(i-k >= 0 && j+k < m && onv[i-k][j+k]){
adj[onh[i][j]].push_back(onv[i-k][j+k]);
adj[onv[i-k][j+k]].push_back(onh[i][j]);
}
}
}
}
}
int ans = 0;
vector<int> label(cnt+1, 0);
for(int i=1; i<=cnt; i++){
if(!vis[i]){
vis[i] = 1;
int cn[2] = {0, 0};
queue<pair<int, int>> q;
q.push({i, 0});
while(q.size()){
auto c = q.front();
cn[c.s]++;
q.pop();
for(int a:adj[c.f]){
if(!vis[a]){
label[a] = 1-c.s;
q.push({a, 1-c.s});
vis[a] = 1;
}
else assert(label[a] == 1-c.s);
}
}
ans += max(cn[0], cn[1]);
}
}
cout<<ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |