結果

問題 No.348 カゴメカゴメ
ユーザー LayCurseLayCurse
提出日時 2016-02-26 22:47:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 3,723 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 163,748 KB
実行使用メモリ 146,260 KB
最終ジャッジ日時 2023-10-24 05:24:36
合計ジャッジ時間 6,530 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
97,616 KB
testcase_01 AC 13 ms
40,568 KB
testcase_02 AC 95 ms
82,164 KB
testcase_03 AC 86 ms
43,364 KB
testcase_04 AC 12 ms
36,776 KB
testcase_05 AC 11 ms
36,776 KB
testcase_06 AC 11 ms
40,548 KB
testcase_07 AC 12 ms
40,548 KB
testcase_08 AC 11 ms
36,452 KB
testcase_09 AC 12 ms
40,556 KB
testcase_10 AC 12 ms
40,552 KB
testcase_11 AC 11 ms
40,552 KB
testcase_12 AC 14 ms
41,688 KB
testcase_13 AC 12 ms
40,776 KB
testcase_14 AC 11 ms
40,584 KB
testcase_15 AC 133 ms
146,260 KB
testcase_16 AC 14 ms
40,548 KB
testcase_17 AC 11 ms
40,548 KB
testcase_18 AC 12 ms
40,548 KB
testcase_19 AC 11 ms
40,548 KB
testcase_20 AC 11 ms
40,564 KB
testcase_21 AC 12 ms
40,556 KB
testcase_22 AC 11 ms
40,548 KB
testcase_23 AC 76 ms
52,796 KB
testcase_24 AC 78 ms
52,548 KB
testcase_25 AC 77 ms
52,400 KB
testcase_26 AC 76 ms
50,704 KB
testcase_27 AC 77 ms
52,936 KB
testcase_28 AC 77 ms
53,436 KB
testcase_29 AC 77 ms
52,136 KB
testcase_30 AC 78 ms
53,572 KB
testcase_31 AC 78 ms
52,988 KB
testcase_32 AC 75 ms
52,188 KB
testcase_33 AC 18 ms
41,964 KB
testcase_34 AC 16 ms
41,628 KB
testcase_35 AC 15 ms
41,424 KB
testcase_36 AC 16 ms
41,708 KB
testcase_37 AC 16 ms
41,992 KB
testcase_38 AC 16 ms
41,992 KB
testcase_39 AC 16 ms
41,568 KB
testcase_40 AC 16 ms
41,848 KB
testcase_41 AC 16 ms
41,724 KB
testcase_42 AC 16 ms
41,644 KB
testcase_43 AC 12 ms
40,720 KB
testcase_44 AC 10 ms
40,724 KB
testcase_45 AC 11 ms
40,716 KB
testcase_46 AC 11 ms
40,740 KB
testcase_47 AC 11 ms
40,776 KB
testcase_48 AC 11 ms
40,740 KB
testcase_49 AC 14 ms
40,712 KB
testcase_50 AC 14 ms
40,764 KB
testcase_51 AC 11 ms
40,724 KB
testcase_52 AC 11 ms
40,732 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void reader(double*)’:
main.cpp:15:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 | void reader(double *x){scanf("%lf",x);}
      |                        ~~~~~^~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

#define ll long long
#define ull unsigned ll

void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(double *x){scanf("%lf",x);}
int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;}
template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);}
template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);}
template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);}

void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(double x, char c){printf("%.15f",x);mypc(c);}
void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);}
void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);}
template<class T> void writerLn(T x){writer(x,'\n');}
template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');}
template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');}

char memarr[17000000]; void *mem = memarr;
#define MD 1000000007

int X, Y;
char mp[1111][1111];

int dx[8] = {0,0,1,-1,1,1,-1,-1};
int dy[8] = {1,-1,0,0,1,-1,1,-1};


int nul(int a, int b, char f, char t, int d, int st[], int &sts){
  int i,res = 0;

  if(a < 0 || b < 0 || a >= X || b >= Y) return res;
  if(mp[a][b] != f){
    if(mp[a][b]=='x'){
      st[sts++] = a*1111+b;
      mp[a][b] = 'y';
    }
    return res;
  }

  mp[a][b] = t;
  res++;

  rep(i,d) res += nul(a+dx[i],b+dy[i],f,t,d,st,sts);
  return res;
}

int node;
vector<int> edge[1111111];
int es[1111111], gain[1111111];

void gen_graph(int st[], int sts, int bef){
  int i, j, k, g;
  int *sss = st + sts;
  int ssz;
  
  rep(k,sts){
    i = st[k] / 1111;
    j = st[k] % 1111;
    if(mp[i][j] != 'y') continue;

    ssz = 0;
    g = nul(i,j,'y','.',8,sss,ssz);
    es[node] = 0;
    gain[node] = g;
    if(bef!=-1) edge[bef].push_back(node);
    node++;

    ssz = 0;
    nul(i,j,'.','@',4,sss,ssz);
    gen_graph(sss,ssz,node-1);
  }
}

int st[1111111], sts;

int dp0[1111111], dp1[1111111];
int solve(int now, int bef){
  int i, j, k;

  dp0[now] = 0;
  dp1[now] = gain[now];
  rep(i,edge[now].size()){
    j = edge[now][i];
    if(j==bef) continue;
    solve(j, now);
    dp0[now] += dp1[j];
    dp1[now] += dp0[j];
  }

  dp1[now] = max(dp0[now], dp1[now]);
  return dp1[now];
}

int main(){
  int i, j, k;
  int res;

  reader(&X,&Y);
  X += 2;
  Y += 2;
  REP(i,1,X-1) reader(mp[i]+1);

  rep(i,Y) mp[0][i] = mp[X-1][i] = '.';
  rep(i,X) mp[i][0] = mp[i][Y-1] = '.';

  node = 1;
  sts = 0;
  nul(0,0,'.','@',4,st,sts);
  gen_graph(st, sts, 0);

  res = solve(0,-1);
  writerLn(res);

  return 0;
}
0