結果

問題 No.110 しましまピラミッド
コンテスト
ユーザー akakimidori
提出日時 2017-06-21 01:38:40
言語 C90(gcc15)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 787 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 188 ms
コンパイル使用メモリ 38,888 KB
最終ジャッジ日時 2026-02-24 00:43:31
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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