Submission #939256

#TimeUsernameProblemLanguageResultExecution timeMemory
939256vjudge1Dango Maker (JOI18_dango_maker)C++17
0 / 100
62 ms144212 KiB
#include <bits/stdc++.h> #pragma optimize("Ofast") #pragma target("avx2") using namespace std; #define ll long long #define ld long double #define pb push_back #define pf push_front #define pii pair<int,int> #define all(v) v.begin(),v.end() #define F first #define S second #define mem(a,i) memset(a,i,sizeof(a)) #define sz(s) (int)s.size() #define y1 yy #define ppb pop_back #define lb lower_bound #define ub upper_bound #define gcd(a,b) __gcd(a,b) #define in insert // #define int ll const int MAX=3000+15; const int B=2e5; const int N=104; const int block=450; const int maxB=MAX/B+10; const ll inf=1e9; const int mod=1e9+7; const int mod1=1e9+9; const ld eps=1e-9; int dx[8]={1,0,-1,0,1,-1,-1,1}; int dy[8]={0,1,0,-1,1,-1,1,-1}; int binpow(int a,int n){ if(!n)return 1; if(n%2==1)return a*binpow(a,n-1); int k=binpow(a,n/2); return k*k; } int n,m; int a[MAX][MAX]; vector<int> g[MAX*MAX*2/3]; int cnt0,cnt1; bool use[MAX*MAX*2/3]; int dp[MAX*MAX*2/3][2]; int was[MAX*MAX*2]; int cur=0; int sum=0; int pos(int i,int j,int f){ return (i-1)*m+j+f*n*m; } void add(int x,int y){ g[x].pb(y); g[y].pb(x); } int getU(int i,int j){ if(a[i][j]==0){ if(i+2>n)return -1; if(a[i+1][j]==1&&a[i+2][j]==2)return i; return -1; } if(a[i][j]==1){ if(i-1<1||i+1>n)return -1; if(a[i-1][j]==0&&a[i+1][j]==2)return i-1; return -1; } if(a[i][j]==2){ if(i-2<1)return -1; if(a[i-2][j]==0&&a[i-1][j]==1)return i-2; } return -1; } int getL(int i,int j){ if(a[i][j]==0){ if(j+2>m)return -1; if(a[i][j+1]==1&&a[i][j+2]==2)return j; return -1; } if(a[i][j]==1){ if(j-1<1||j+1>m)return -1; if(a[i][j-1]==0&&a[i][j+1]==2)return j-1; return -1; } if(a[i][j]==2){ if(j-2<1)return -1; if(a[i][j-2]==0&&a[i][j-1]==1)return j-2; return -1; } return -1; } void dfs(int v,int c=0){ use[v]=1; if(c==0)cnt0++; else cnt1++; sum+=sz(g[v]); for(auto to:g[v]){ if(!use[to]){ dfs(to,c^1); dp[v][0]+=max(dp[to][0],dp[to][1]); dp[v][1]+=dp[to][0]; } } dp[v][1]++; } void solve(){ cin>>n>>m; for(int i=1;i<=n;i++){ string s; cin>>s; for(int j=1;j<=m;j++){ if(s[j-1]=='R')a[i][j]=0; else if(s[j-1]=='G')a[i][j]=1; else a[i][j]=2; } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ int l1=getU(i,j),l2=getL(i,j); if(l1!=-1&&!was[pos(l1,j,1)]){ was[pos(l1,j,1)]=++cur; } if(l2!=-1&&!was[pos(i,l2,0)]){ // cout<<cur<<'\n'; was[pos(i,l2,0)]=++cur; // cout<<i<<" "<<l2<<" "<<was[pos(i,l2,0)]<<"\n"; } if(l1!=-1&&l2!=-1){ add(was[pos(l1,j,1)],was[pos(i,l2,0)]); } } } // cout<<cur<<"\n"; int ans=0; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ // if(i==4&&j==2){ // cout<<i<<" "<<j<<" "<<was[pos(i,j,0)]<<"\n"; // } if(!use[was[pos(i,j,0)]]&&was[pos(i,j,0)]){ int v=was[pos(i,j,0)]; // cout<<i<<" "<<j<<"\n"; cnt0=cnt1=sum=0; dfs(was[pos(i,j,0)]); if(sum!=2*(cnt0+cnt1-1)){ cout<<"WTFFF\n"; return; } ans+=max(dp[v][0],dp[v][1]); } if(!use[was[pos(i,j,1)]]&&was[pos(i,j,1)]){ int v=was[pos(i,j,0)]; cnt0=cnt1=sum=0; dfs(was[pos(i,j,1)]); if(sum!=2*(cnt0+cnt1-1)){ cout<<"WTFFF\n"; return; } ans+=max(dp[v][0],dp[v][1]); } } } cout<<ans; } //1010 //0011 signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // prec(); int t=1; // cin>>t; while(t--)solve(); }

Compilation message (stderr)

dango_maker.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    3 | #pragma optimize("Ofast")
      | 
dango_maker.cpp:4: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    4 | #pragma target("avx2")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...