結果

問題 No.233 めぐるはめぐる (3)
ユーザー tsuishitsuishi
提出日時 2021-01-19 12:47:34
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 3,446 bytes
コンパイル時間 1,240 ms
コンパイル使用メモリ 29,800 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-22 10:20:40
合計ジャッジ時間 4,811 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,760 KB
testcase_01 AC 8 ms
4,380 KB
testcase_02 AC 5 ms
4,376 KB
testcase_03 AC 10 ms
4,376 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>
// ***********************
// for debug
#define DEBUG2
#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)

// 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    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<(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 (8*128+2)
// ***********************
// 外部変数
// ***********************
// ***********************
int cnt1 = 12;
int cnt2 = 60000;

void strchange( char str[] ) {
    int i;
    int k;
    do {
        cnt1++;
        if( cnt1 > 121 ) {
            cnt1 = 0;
            cnt2--;
        }

        i = cnt1 % 11;
        k = (cnt1 / 11) % 11;
        if( (i & 1 )!= (k & 1) ) continue;
        if( i == k ) continue;

  
   TRACE("change %d,%d [%s]",i,k,str);
        SWAP( char , str[i] , str[k] );
        TRACE("[%s]\n",str);
        break;
    } while(1);
}
// ***********************
// ***********************
int onaji( char str[] , void *mp , int limit ) {
    unsigned char   *cp;
    
    cp = (char *)mp;
    REP(i,limit) {
        int onaflg = 1;
        REP(k,13) if( *(cp+ k) != str[k] ) { onaflg = 0; break; }
        if( onaflg ) {
            TRACE("%s == %s\n",cp , str);
            return 1;  // 同じものがある
        }
        cp += 13;
    }
    return 0;   // 同じものがない
}
// ***********************
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 ) ) == NULL ) return 13;
        mp = mem;
        REP(i,query) {
            scanf("%s", mp );
            //TRACE("get[%s]\n", mp);
            mp += 13;
        }
    /*
    REP(i,400) {
        strchange( name );
        printf("%s\n",name);
    }
    */
        do {
            TRACE("t:%s\n",name);
            strchange( name );
            if( cnt2 < 0 ) {
                printf("NO\n");
                return 0;
            }
        } while( onaji( name, mem , query) );
    }
    printf("%s\n", name );
    free( mem );
	return 0;
}
0