제출 #939573

#제출 시각아이디문제언어결과실행 시간메모리
939573vjudge1Dango Maker (JOI18_dango_maker)C++17
100 / 100
160 ms44900 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];

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;
}

int dp[MAX][2];

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;
    }
  }
  int ans=0;
  for(int i=1;i<=n;i++){
    mem(dp,0);
    int x=i,y=1;
    while(x>=1&&y<=m){
      dp[y][0]=dp[y-1][0];
      dp[y][1]=dp[y-1][1];
      if(a[x][y]!=2){
        x--;
        y++;
        continue;
      }
      if(getU(x,y)!=-1){
        dp[y][1]=max(dp[y][1],max(dp[y-1][0],dp[y-1][1])+1);
      }
      if(getL(x,y)!=-1){
        dp[y][0]=max(dp[y][0],dp[y-1][0]+1);
        if(y-3>=0)dp[y][0]=max(dp[y][0],dp[y-3][1]+1);
      }
      x--;
      y++;
    }
    y--;
    ans+=max(dp[y][0],dp[y][1]);    
  }
  for(int j=2;j<=m;j++){
    mem(dp,0);
    int x=n,y=j;
    while(x>=1&&y<=m){
      dp[y][0]=dp[y-1][0];
      dp[y][1]=dp[y-1][1];
      if(a[x][y]!=2){
        x--;
        y++;
        continue;
      }
      if(getU(x,y)!=-1){
        dp[y][1]=max(dp[y][1],max(dp[y-1][0],dp[y-1][1])+1);
      }
      if(getL(x,y)!=-1){
        dp[y][0]=max(dp[y][0],dp[y-1][0]+1);
        if(y-3>=0)dp[y][0]=max(dp[y][0],dp[y-3][1]+1);
      }
      x--;
      y++;
    }
    y--;
    ans+=max(dp[y][0],dp[y][1]);    
  }
  cout<<ans;
}

signed main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // prec();
  int t=1;
  // cin>>t;
  while(t--)solve();
}

컴파일 시 표준 에러 (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...