結果

問題 No.233 めぐるはめぐる (3)
ユーザー tsuishitsuishi
提出日時 2021-01-19 15:43:21
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 6,814 bytes
コンパイル時間 423 ms
コンパイル使用メモリ 33,664 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-05-09 18:57:37
合計ジャッジ時間 4,717 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
13,756 KB
testcase_01 AC 9 ms
6,940 KB
testcase_02 AC 6 ms
6,944 KB
testcase_03 AC 11 ms
6,940 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <math.h>
// №
// ***********************
// for debug
#define DEBUGh

#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	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 void read1(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
static void read2(int *x, int *y){read1(x);read1(y);}
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];}

// 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 (30+3)
#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 char	*memory;
static char	*mp;
static long	datacnt;
static char	*moto;
static char	*nowstr;
static char	AL_length;
static char	*flgs;
void ALLsub(int num)
{
    int i;
    if(num==AL_length) {
        strcpy( mp, nowstr );
        //TRACE("%s,",mp);
        mp += (AL_length+1);
        datacnt++;
    } else {
        for(i=0;i<AL_length;i++) {
            if(!flgs[i]) {
                flgs[i]=1;
                nowstr[num] = moto[i];
                ALLsub(num+1);
                flgs[i]=0;
            }
        }
    }
}
void *ALL( char str[] ) {

	long	val;
	char	*fp;

    AL_length = strlen( str );
    val = 1;
    for(int i=1;i<=AL_length;i++) val*=i;
    if( (memory=malloc( val * (AL_length + 1) )) == NULL ) {
		return (void *)NULL;
	}
	mp = memory;
    if( (flgs=(char*)malloc( AL_length )) == NULL ) {
		free( memory );
		return (void *)NULL;
	}
    if( (moto=(char*)malloc( AL_length +1 )) == NULL ) {
		free( memory );
		free( flgs );
		return (void *)NULL;
	}
    if( (nowstr=(char*)malloc( AL_length +1 )) == NULL ) {
		free( moto );
		free( memory );
		free( flgs );
		return (void *)NULL;
	}
	strcpy( moto , str );
	fp = flgs;
	REP(i,AL_length) *fp++ = 0;
	datacnt = 0;
	
	ALLsub(0);
	
	free( nowstr );
	free( moto );
	free( flgs );
	return memory;
}


// ***********************
int onaji( char stro[] , void *mp , int limit ) {
    char   *cp;
    int onaflg;
    
    cp = (char *)mp;
    TRACE("check %s\n", str);
    REP(i,limit) {
        onaflg = 1;
        REP(k,11) if( *(cp+ k) != stro[k] ) { onaflg = 0; break; }
        if( onaflg ) {
            //TRACE("%s == %s\n",cp , str);
            return 1;  // 同じものがある
        }
        //TRACE("%s != %s\n",cp , str);
        cp += 13;
        if( *cp == '\0' ) break;
    }
    return 0;   // 同じものがない
}
// ***********************
int cnt1 = 1;

void strchange( char name[] , char *damestr, int limit ) {
	char *siinn;
	char	*boinn;
	char	*sp,*bp;
	long	sl,bl;
	char	sstr[9] = { "iaaeuu\0\0" };
	char	bstr[8] = { "nbmgr" };
	char	strc[14];


	strc[11] = '\0';
	sp = siinn = ALL( sstr );
	sl = datacnt;
	bp = boinn = ALL( bstr );
	bl = datacnt;

	for(long ll=0; ll < sl ; ll++ ) {
		strcpy( sstr, sp );
		bp =boinn;
		for(long bb=0; bb < bl ; bb++ ) {
			strcpy( bstr, bp );
			strc[0] = sstr[0];
			strc[1] = bstr[0];
			strc[2] = sstr[1];
			strc[3] = bstr[1];
			strc[4] = sstr[2];
			strc[5] = bstr[2];
			strc[6] = sstr[3];
			strc[7] = bstr[3];
			strc[8] = sstr[4];
			strc[9] = bstr[4];
			strc[10] = sstr[5];
			if( onaji( strc , damestr , limit) == 0 ) {
				printf("%s\n", strc);
				free( siinn );
				free( boinn );
				return;
			}
			strc[0] = bstr[0];
			strc[1] = sstr[1];
			strc[2] = bstr[1];
			strc[3] = sstr[2];
			strc[4] = bstr[2];
			strc[5] = sstr[3];
			strc[6] = bstr[3];
			strc[7] = sstr[4];
			strc[8] = bstr[4];
			strc[9] = sstr[5];
			strc[10] = sstr[0];
			if( onaji( strc , damestr , limit) == 0 ) {
				printf("%s\n", strc);
				free( siinn );
				free( boinn );
				return;
			}
			bp += 6;
		}
		sp += 7;
	}
	free( siinn );
	free( boinn );
	printf("NO\n");
}
// ***********************
// ***********************
int main(void) {
    char  name[16];
    char *mem;
    char *mp;

    int query;
    strcpy( name , "inabameguru");

    scanf("%d", &query);

    if( query ) {
        if(( mem = malloc( 13 * (query +1)) ) == NULL ) return 13;
        mp = mem;
        REP(i,query) {
            scanf("%s", mp );
            //TRACE("get[%s]\n", mp);
            mp += 13;
        }
        *mp = '\0';
    }
    strchange( name , mem, query);
    free( mem );
	return 0;
}
0