結果

問題 No.5002 stick xor
ユーザー akakimidoriakakimidori
提出日時 2018-05-26 05:15:46
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 548 ms / 1,000 ms
コード長 2,181 bytes
コンパイル時間 17,602 ms
実行使用メモリ 956 KB
スコア 40,975
最終ジャッジ日時 2018-05-26 05:16:05
ジャッジサーバーID
(参考情報)
judge9 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 548 ms
952 KB
testcase_01 AC 473 ms
952 KB
testcase_02 AC 502 ms
956 KB
testcase_03 AC 488 ms
952 KB
testcase_04 AC 482 ms
956 KB
testcase_05 AC 473 ms
956 KB
testcase_06 AC 466 ms
952 KB
testcase_07 AC 501 ms
956 KB
testcase_08 AC 496 ms
956 KB
testcase_09 AC 493 ms
952 KB
testcase_10 AC 487 ms
952 KB
testcase_11 AC 509 ms
956 KB
testcase_12 AC 515 ms
952 KB
testcase_13 AC 487 ms
956 KB
testcase_14 AC 492 ms
956 KB
testcase_15 AC 474 ms
952 KB
testcase_16 AC 488 ms
952 KB
testcase_17 AC 479 ms
952 KB
testcase_18 AC 486 ms
952 KB
testcase_19 AC 472 ms
956 KB
testcase_20 AC 467 ms
952 KB
testcase_21 AC 484 ms
956 KB
testcase_22 AC 482 ms
956 KB
testcase_23 AC 489 ms
952 KB
testcase_24 AC 482 ms
956 KB
testcase_25 AC 481 ms
956 KB
testcase_26 AC 509 ms
956 KB
testcase_27 AC 490 ms
952 KB
testcase_28 AC 503 ms
956 KB
testcase_29 AC 494 ms
956 KB
testcase_30 AC 484 ms
956 KB
testcase_31 AC 471 ms
956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

#define POS(i,j) ((i)*(n+1)+(j))

typedef struct length{
  int l;
  int index;
} len;

int cmp(const void *a,const void *b){
  return -(((len *)a)->l-((len *)b)->l);
}

void flip(int l,char *s,int n,int *t){
  int a=t[0];
  int b=t[1];
  if(a==t[2]){
    int i;
    for(i=0;i<l;i++){
      int index=POS(a,b+i);
      s[index]=s[index]=='0'?'1':'0';
    }
  } else {
    int i;
    for(i=0;i<l;i++){
      int index=POS(a+i,b);
      s[index]=s[index]=='0'?'1':'0';
    }
  }
  return;
}

void func(int l,char *s,const int n,int *a){
  int max=-l-1;
  int i,j,k;
  for(i=0;i<n-l+1;i++){
    for(j=0;j<n;j++){
      int c=0;
      for(k=0;k<l;k++){
	c+=(s[POS(i+k,j)]=='0'?-1:1);
      }
      if(c>max){
	max=c;
	a[0]=i;
	a[1]=j;
	a[2]=i+l-1;
	a[3]=j;
      }
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n-l+1;j++){
      int c=0;
      for(k=0;k<l;k++){
	c+=(s[POS(i,j+k)]=='0'?-1:1);
      }
      if(c>max){
	max=c;
	a[0]=i;
	a[1]=j;
	a[2]=i;
	a[3]=j+l-1;
      }
    }
  }
  flip(l,s,n,a);
  return;
}

void run(void){
  int n,k;
  scanf("%d%d",&n,&k);
  char *s=(char *)calloc((n+1)*n,sizeof(char));
  len *array=(len *)malloc(sizeof(len)*k);
  int *ans=(int *)malloc(sizeof(int)*4*k);
  int i;
  for(i=0;i<k;i++){
    int t;
    scanf("%d",&t);
    array[i].l=t;
    array[i].index=i;
  }
  qsort(array,k,sizeof(len),cmp);
  for(i=0;i<n;i++) scanf("%s",s+POS(i,0));

  const int parameter=4;
  for(i=0;i<k && array[i].l>=parameter;i++){
    int l=array[i].l;
    int index=array[i].index;
    func(l,s,n,ans+4*index);
  }
  const int m=i;

  int iter=15;
  while(iter--){
    for(i=0;i<m;i++){
      int l=array[i].l;
      int index=array[i].index;
      flip(l,s,n,ans+4*index);
      func(l,s,n,ans+4*index);
    }
  }
  for(i=m;i<k;i++){
    int l=array[i].l;
    int index=array[i].index;
    func(l,s,n,ans+4*index);
  }

  for(i=0;i<k;i++){
    printf("%d %d %d %d\n",ans[i*4+0]+1,ans[i*4+1]+1,ans[i*4+2]+1,ans[i*4+3]+1);
  }
  return;
}

int main(void){
  run();
  return 0;
}
0