結果

問題 No.110 しましまピラミッド
ユーザー akakimidori
提出日時 2017-06-21 01:38:40
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 787 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 21,632 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-31 11:31:53
合計ジャッジ時間 1,126 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘run’:
main.c:36:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |   scanf("%d",&n);
      |   ^~~~~~~~~~~~~~
main.c:39:20: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |   for(i=0;i<n;i++) scanf("%d",w+i);
      |                    ^~~~~~~~~~~~~~~
main.c:42:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   42 |   scanf("%d",&m);
      |   ^~~~~~~~~~~~~~
main.c:44:20: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |   for(i=0;i<m;i++) scanf("%d",b+i);
      |                    ^~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>

#define MAX(a,b) ((a)>(b)?(a):(b))

int calc(int *a,int n,int *b,int m){
  int res=1;
  int s=n-1;
  int t=m-1;
  while(1){
    while(t>=0 && a[s]<=b[t]) t--;
    if(t<0) return res;
    res++;
    while(s>=0 && b[t]<=a[s]) s--;
    if(s<0) return res;
    res++;
  }
  return 0;
}

void sort(int *a,int n){
  int i,j;
  for(i=1;i<n;i++){
    int p=a[i];
    j=i-1;
    while(j>=0 && p<a[j]){
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=p;
  }
  return;
}

void run(void){
  int n;
  scanf("%d",&n);
  int w[10];
  int i;
  for(i=0;i<n;i++) scanf("%d",w+i);

  int m;
  scanf("%d",&m);
  int b[10];
  for(i=0;i<m;i++) scanf("%d",b+i);

  sort(w,n);
  sort(b,m);
  printf("%d\n",MAX(calc(w,n,b,m),calc(b,m,w,n)));
  return;
}

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