結果
| 問題 |
No.110 しましまピラミッド
|
| コンテスト | |
| ユーザー |
tsuishi
|
| 提出日時 | 2021-02-02 14:20:52 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 5,255 bytes |
| コンパイル時間 | 187 ms |
| コンパイル使用メモリ | 33,024 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-29 23:40:29 |
| 合計ジャッジ時間 | 1,205 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <ctype.h>
#include <math.h>
// Yukicoder №110 No.110 しましまピラミッド
// https://yukicoder.me/problems/no/110
// ***********************
// for debug
#define DEBUG7
#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 ctime(...) ctime_s(...)
#define strlen(a) mystr_len(a)
//#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)
#define mygc(c) (c)=getchar()
static char *getinput( char* str );
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];}
static int max(int a,int b){if(a>b){return a;}return b;}
static int min(int a,int b){if(a<b){return a;}return b;}
// for readaility
typedef long long lolong;
const int INF = 1e9;
const int MOD = 1e9+7;
const lolong LINF = 1e18;
#define PI ((double)3.141592653589793238462643383279)
#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)
#define ABS(c) ((c)<0?(-(c)):(c))
#define LSB(i) ((i) & -(i))
#define INPBUF (250+2)
#define data_s int
// ***********************
// ***********************
static int cmpint_asc(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
static int cmpint_desc(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
static int cmpchar_asc(const void *a,const void *b){if(*(char *)a>*(char *)b){return 1;}if(*(char *)a==*(char *)b){return 0;}return -1;}
static int cmpchar_desc(const void *a,const void *b){if(*(char *)a<*(char *)b){return 1;}if(*(char *)a==*(char *)b){return 0;}return -1;}
static int mystr_len(char *str){int i=0;do{if(str[i]=='\0')break;i++;if(i>9999)break;}while(1);return i;}
static int countchar(char str[],char c,int limit ) {int cnt = 0;for(int i=0;i<limit;i++) if( str[i] == c )cnt++;return cnt;}
// ***********************
typedef struct HOGE {
int num;
int color;
} BLOCK_t;
// ***********************
// ***********************
// ***********************
// ***********************
// ***********************
// 外部変数
// ***********************
// ***********************
// ***********************
int cmpblock( const void *ap, const void *bp ) {
int a,b;
BLOCK_t *d;
d =(BLOCK_t*)ap;
a = d->num;
d =(BLOCK_t*)bp;
b = d->num;
#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() {
char str[INPBUF];
int queryW,queryB,blocks;
BLOCK_t block[20];
int col;
int cnt;
int prevnum;
int imax = 0;
int idx;
INPUT( str );
sscanf( str,"%d", &queryW );
REP(i,queryW) {
getinput( str );
sscanf( str,"%d", & block[i].num );
block[i].color = 1;
}
INPUT( str );
sscanf( str,"%d", &queryB );
REP(i,queryB) {
getinput( str );
sscanf( str,"%d", & block[i+queryW].num );
block[i+queryW].color = 0;
}
blocks = queryW + queryB;
qsort( block , blocks, sizeof( block[0] ), cmpblock );
//REP(k,blocks) TRACE("block[%d].num=%d , block[%d].color = %d\n",k,block[k].num,k,block[k].color);
// case top white
col = -1; cnt =0;
for(idx=0; idx < blocks ; idx++) if( block[ idx ].color == 1 ) { col = 1; prevnum = block[idx].num; break; }
if( col >= 0 ) {
cnt++;
col = 0;
for(idx++; idx < blocks ; idx++) {
if( block[ idx].num == prevnum ) continue;
if( block[ idx ].color == col ) {
prevnum = block[ idx ].num;
col = 1 - col;
cnt++;
}
}
}
TRACE("white mode cnt %d\n",cnt);
imax = max( 0, cnt );
// case top black
col = -1; cnt =0;
for(idx=0; idx < blocks ; idx++) if( block[ idx ].color == 0 ) { col = 0; prevnum = block[idx].num; break; }
if( col >= 0 ) {
cnt++;
col = 1;
for(idx++; idx < blocks ; idx++) {
if( block[ idx].num == prevnum ) continue;
if( block[ idx ].color == col ) {
prevnum = block[ idx ].num;
col = 1 - col;
cnt++;
}
}
}
TRACE("black mode cnt %d\n",cnt);
imax = max( imax, cnt );
printf("%d\n", imax );
return 0;
}
tsuishi