結果

問題 No.360 増加門松列
ユーザー notetonousnotetonous
提出日時 2016-04-18 00:32:09
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 919 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 25,264 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 18:36:36
合計ジャッジ時間 1,088 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 0 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 0 ms
4,376 KB
testcase_08 AC 0 ms
4,376 KB
testcase_09 AC 0 ms
4,376 KB
testcase_10 AC 0 ms
4,384 KB
testcase_11 AC 0 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 0 ms
4,384 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 0 ms
4,376 KB
testcase_16 AC 0 ms
4,376 KB
testcase_17 AC 0 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
int next_perm(int *p, int n)
{
  int i, j, k, tmp;
  for(i = n - 1; i > 0 && p[i-1] >= p[i]; i--);
  if(i == 0) return 0;
  for(j = n - 1; j > i && p[i-1] >= p[j]; j--);
  tmp = p[i-1], p[i-1] = p[j], p[j] = tmp;
  for(k = 0; k <= ((n-1)-i)/2; k++)
    tmp = p[i+k], p[i+k] = p[(n-1)-k], p[(n-1)-k] = tmp;
  return 1;
}

int check(int a[7]){
  int i;
 for(i=0;i<5;i++){
   if( (( a[i]<a[i+2] ) && (( a[i] < a[i+1] && a[i+1] > a[i+2] ) || ( a[i] > a[i+1] &&  a[i+1] < a[i+2] ))) == 0 ) return 0;
    
 }
 return 1;  
}

int main(){
  int i,j;
  int d[7];
  int tmp;
  for(i=0;i<7;i++)scanf("%d",&d[i]);
  for (i = 0; i < 7; i++) {
    for (j = 6; j > i; j--) {
      if (d[j - 1] > d[j]) { 
	tmp = d[j];       
	d[j] = d[j - 1];
	d[j - 1]= tmp;
      }
    }	  
  }
  
  while(next_perm(d, 7)){
  
    if(check(d)==1){
      printf("YES\n");
      return 0;
    }
  }
  printf("NO\n");
  return 0;
}

0