Submission #939193

# Submission time Handle Problem Language Result Execution time Memory
939193 2024-03-06T06:40:19 Z vjudge1 Dango Maker (JOI18_dango_maker) C++17
0 / 100
86 ms 262144 KB
#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];
int cnt0,cnt1;
bool use[MAX*MAX*2];
bool was[MAX*MAX*2];

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++;
  for(auto to:g[v]){
    if(!use[to])dfs(to,c^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)]=1;
      }
      if(l2!=-1){
        was[pos(i,l2,0)]=1;
      }
      if(l1!=-1&&l2!=-1){
        add(pos(l1,j,1),pos(i,l2,0));
      }
    }
  }
  int ans=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(!use[pos(i,j,0)]&&was[pos(i,j,0)]){
        cnt0=cnt1=0;
        dfs(pos(i,j,0));
        ans+=max(cnt0,cnt1);
      }
      if(!use[pos(i,j,1)]&&was[pos(i,j,1)]){
        cnt0=cnt1=0;
        dfs(pos(i,j,0));
        ans+=max(cnt0,cnt1);  
      }
    }
  }
  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

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 time Memory Grader output
1 Runtime error 86 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 86 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 86 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -