CODE FESTIVAL 2016 Final

Submission #3911799

Source codeソースコード

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

#define MIN(a,b) ((a)<(b)?(a):(b))

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

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  int *x=(int *)calloc(n,sizeof(int));
  int i;
  for(i=0;i<n;i++) scanf("%d",x+i);
  int *cnt=(int *)calloc(m,sizeof(int));
  for(i=0;i<n;i++) if(x[i]) cnt[x[i]%m]++;
  int ans=cnt[0]/2;
  cnt[0]%=2;
  for(i=1;i<m-i;i++){
    int k=MIN(cnt[i],cnt[m-i]);
    ans+=k;
    cnt[i]-=k;
    cnt[m-i]-=k;
  }
  if(m%2==0){
    ans+=cnt[m/2]/2;
    cnt[m/2]%=2;
  }
  qsort(x,n,sizeof(int),cmp);
  i=0;
  while(i+1<n){
    if(x[i]==x[i+1] && cnt[x[i]%m]>=2){
      ans++;
      cnt[x[i]%m]-=2;
      i+=2;
    } else {
      i++;
    }
  }
  printf("%d\n",ans);
}

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

Submission

Task問題 D - Pair Cards
User nameユーザ名 sansen
Created time投稿日時
Language言語 C (GCC 5.4.1)
Status状態 AC
Score得点 700
Source lengthソースコード長 839 Byte
File nameファイル名
Exec time実行時間 25 ms
Memory usageメモリ使用量 1404 KB

Compiler messageコンパイルメッセージ

./Main.c: In function ‘run’:
./Main.c:12:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
^
./Main.c:15:20: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
for(i=0;i<n;i++) scanf("%d",x+i);
^

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt
all 700 / 700 sample-01.txt,sample-02.txt,01-01.txt,01-02.txt,01-03.txt,01-04.txt,01-05.txt,01-06.txt,01-07.txt,01-08.txt,01-09.txt,01-10.txt,01-11.txt,01-12.txt,01-13.txt,01-14.txt,01-15.txt,01-16.txt,01-17.txt,01-18.txt,01-19.txt,01-20.txt,01-21.txt,01-22.txt,01-23.txt,01-24.txt,01-25.txt,01-26.txt,01-27.txt,01-28.txt,01-29.txt,01-30.txt,sample-01.txt,sample-02.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 1 ms 128 KB
01-02.txt AC 24 ms 892 KB
01-03.txt AC 24 ms 892 KB
01-04.txt AC 23 ms 892 KB
01-05.txt AC 23 ms 892 KB
01-06.txt AC 25 ms 892 KB
01-07.txt AC 23 ms 892 KB
01-08.txt AC 24 ms 892 KB
01-09.txt AC 24 ms 892 KB
01-10.txt AC 24 ms 1148 KB
01-11.txt AC 24 ms 1276 KB
01-12.txt AC 15 ms 764 KB
01-13.txt AC 15 ms 892 KB
01-14.txt AC 23 ms 892 KB
01-15.txt AC 23 ms 892 KB
01-16.txt AC 23 ms 892 KB
01-17.txt AC 23 ms 892 KB
01-18.txt AC 23 ms 892 KB
01-19.txt AC 23 ms 1020 KB
01-20.txt AC 23 ms 1276 KB
01-21.txt AC 22 ms 892 KB
01-22.txt AC 22 ms 892 KB
01-23.txt AC 22 ms 892 KB
01-24.txt AC 23 ms 892 KB
01-25.txt AC 22 ms 1020 KB
01-26.txt AC 23 ms 1404 KB
01-27.txt AC 12 ms 892 KB
01-28.txt AC 2 ms 636 KB
01-29.txt AC 1 ms 384 KB
01-30.txt AC 1 ms 512 KB
sample-01.txt AC 1 ms 128 KB
sample-02.txt AC 1 ms 128 KB