結果

問題 No.1285 ゴミ捨て
ユーザー tsuishitsuishi
提出日時 2020-12-24 14:28:20
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 3,241 bytes
コンパイル時間 614 ms
コンパイル使用メモリ 28,404 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-19 07:28:42
合計ジャッジ時間 2,040 ms
ジャッジサーバーID
(参考情報)
judge9 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// ***********************
// for debug
#define DEBUGz


#define NOP do{}while(0)
#ifdef DEBUG
#define TRACE(...) do{printf(__VA_ARGS__);fflush(stdout);}while(0)
#define TRACECR do{printf("\n");fflush(stdout);}while(0)
#else
#define TRACE(...) NOP
#define TRACECR NOP
#endif

#define PRINCR printf("\n")
#define NOCR(strig) do{char *p;p=strchr(strig,'\n');if(p)*p='\0';}while(0)
// The out-of-date function
#define	asctime(...)	asctime_s(...)
#define	atof(a)		strtod(a,'\0')
#define	atoi(a)		((int)strtol(a,'\0'))
#define	atol(a)		strtol(a,'\0')
#define	ctime(...)		ctime_s(...)
//#define	fopen(...)		fopen_s(...)
//#define	freopen(...)	freopen_s(...)
//#define	rewind(a)		fseek(a,0L,SEEK_SET)
//#define	setbuf(a,b)		setvbuf(a,b,_IOFBF,BUFSIZ)

// for stdio
#define INPUT(str) do{char *p;fgets(str,sizeof(str),stdin);p=strchr(str,'\n');if(p)*p='\0';}while(0)
static char *getinput( char* str );

// for readaility
typedef	long long	lolong;
const int	INF = 1e9;
const int	MOD = 1e9+7;
const lolong	LINF = 1e18;
#define	YES(a)	printf("%s",((a)?"YES":"NO"))
#define	Yes(a)	printf("%s",((a)?"Yes":"No"))
#define OK(a)	printf("%s",((a)?"OK":"NG"))
#define Ok(a)	printf("%s",((a)?"Ok":"Ng"))
#define	POSSIBLE(a)		printf("%s",((a)?"POSSIBLE":"IMPOSSIBLE"))
#define	Possible(a)		printf("%s",((a)?"Possible":"Impossible"))
#define SWAP(type,a,b) do{type _c;_c=a;a=b;b=_c;}while(0)
#define REP(a,b) for(int a=0;a<(int)(b);++a)
#define REP1(a,b) for(int a=1;a<=(b);++a)
#define FLOOP(a,b) for(a=0;a<(b);++a)
#define FLOOP1(a,b) for(a=1;a<=(b);++a)


// ***********************
// stdioから空白区切りの単語を1つだけ読み取ってくる(可変長入力の場合)
static char *getinput( char* str ) {
	char c;
	char *cp;
	cp = &str[0];
	c = fgetc(stdin);
	while( c != EOF ) {
		if( ( c == ' ')||( c == '\n') ) break;
		*cp++ = c;
		c = fgetc(stdin);
	}
	*cp = '\0';
	return &str[0];
}
// ***********************
// 個別リテラル
#define INPBUF (11+2)
// ***********************
// 外部変数
// ***********************
int	cmpint( const void *av, const void *bv ) {
    int a,b;
    a = *(int*)(av);
    b = *(int*)(bv);
#if 0
    // 1 is 降順 5 4 3 2 1
    if( a > b ) return -1;
    else if( a < b ) return 1;
    else return 0;
#else
    // 0 is 昇順 1 2 3 4 5
    if( a < b ) return -1;
    else if( a > b ) return 1;
    else return 0;
#endif
}
// ***********************
// ***********************
int main(void){
	char str[INPBUF];
	int	val;
	int query;
	int	*datas;
	int	*datap;
	int zenkai;
	// init
	// ready
	INPUT(str); sscanf( str , "%d", &query );
	if( (datas = malloc( query * sizeof(int) )) == NULL ) {
		return 12;
	}
	// start
	datap = datas;	// reset
	REP(i,query) {
		INPUT(str); sscanf( str , "%d", &val );
		*datap++ = val;
	}
    //REP(i,query) {
	//    printf("%d ",datas[i]);
	//} PRINCR;
	qsort( datas , query , sizeof(int) , cmpint );
	//REP(i,query) {
	//    printf("%d ",datas[i]);
	//} PRINCR;
	datap = datas;	// reset
	val = 1;
	zenkai = datap[0];
	for(int i = 1; i < query; ++i) {
		if( zenkai+1  < datap[i]  ) {
			NOP;
		} else {
		    val = 2;
		    break;
		}
		zenkai = datap[i];
	}
	printf("%d\n",val);
	free(datas);
	return 0;
}
0