Submission #284252

#TimeUsernameProblemLanguageResultExecution timeMemory
284252YJUDango Maker (JOI18_dango_maker)C++14
0 / 100
1 ms384 KiB
#include<bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; const ll MOD=1e9+7; const ll MOD2=998244353; const ll N=3e3+5; const ld pi=3.14159265359; const ll INF=(1LL<<60); #define SQ(i) ((i)*(i)) #define REP(i,n) for(ll i=0;i<n;i++) #define REP1(i,n) for(ll i=1;i<=n;i++) #define pb push_back #define mp make_pair #define X first #define Y second #define setp setprecision #define lwb lower_bound #define SZ(_a) (ll)_a.size() map<ll,vector<ll> > v; map<ll,ll> col; ll cnt[3],n,m,ans; vector<ll> point; char c[N][N]; bool valid(ll xa,ll ya,ll xb,ll yb){ if(xa>xb)swap(xa,xb); if(ya>yb)swap(ya,yb); ll xm=(xa+xb)/2,ym=(ya+yb)/2; if(xa<0||xb>=n||ya<0||yb>=m||c[xm][ym]!='G')return 0; if(ya==yb){ return ((c[xa][ym]=='R'&&c[xb][ym]=='W')||c[xa][ym]=='W'&&c[xb][ym]=='R'); }else{ return ((c[xm][ya]=='R'&&c[xm][yb]=='W')||c[xm][ya]=='W'&&c[xm][yb]=='R'); } } void DFS(ll nd){ ++cnt[col[nd]]; for(auto i:v[nd]){ if(col[i]==0){ col[i]=3-col[nd]; DFS(i); } } } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>m; REP(i,n)REP(j,m){ cin>>c[i][j]; } REP(i,n)REP(j,m){ ll nd=i*m+j; if(c[i][j]=='G'){ if(valid(i-1,j,i+1,j)&&valid(i,j-1,i,j+1)){ v[nd*2].pb(nd*2+1); v[nd*2+1].pb(nd*2); } if(valid(i-1,j,i+1,j))point.pb(nd*2); if(valid(i,j-1,i,j+1))point.pb(nd*2+1); }else{ vector<ll> tmp; if(valid(i-2,j,i,j))tmp.pb(2*((i-1)*m+j)); if(valid(i,j,i+2,j))tmp.pb(2*((i+1)*m+j)); if(valid(i,j-2,i,j))tmp.pb(2*(i*m+(j-1))+1); if(valid(i,j,i,j+2))tmp.pb(2*(i*m+(j+1))+1); for(auto ii:tmp)for(auto jj:tmp){ if(ii==jj)continue; v[ii].pb(jj);v[jj].pb(ii); } } } for(auto i:point){ cnt[1]=cnt[2]=0; if(col[i]==0){ col[i]=1; DFS(i); ans+=max(cnt[1],cnt[2]); } } cout<<ans<<"\n"; return 0; }

Compilation message (stderr)

dango_maker.cpp: In function 'bool valid(ll, ll, ll, ll)':
dango_maker.cpp:36:59: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   36 |   return ((c[xa][ym]=='R'&&c[xb][ym]=='W')||c[xa][ym]=='W'&&c[xb][ym]=='R');
      |                                             ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
dango_maker.cpp:38:59: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   38 |   return ((c[xm][ya]=='R'&&c[xm][yb]=='W')||c[xm][ya]=='W'&&c[xm][yb]=='R');
      |                                             ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...