結果

問題 No.2715 Unique Chimatagram
コンテスト
ユーザー 👑 tails
提出日時 2024-04-05 23:34:15
言語 C90(gcc15)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,227 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 78 ms
コンパイル使用メモリ 26,292 KB
最終ジャッジ日時 2026-02-24 01:18:49
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.c: In function 'f0':
main.c:32:13: error: expected ';' before 'i'
   32 |         rep(i,26){
      |             ^
main.c:6:32: note: in definition of macro 'rep'
    6 | #define rep(v,e) for(typeof(e) v=0;v<e;++v)
      |                                ^
main.c:32:13: error: 'i' undeclared (first use in this function)
   32 |         rep(i,26){
      |             ^
main.c:6:36: note: in definition of macro 'rep'
    6 | #define rep(v,e) for(typeof(e) v=0;v<e;++v)
      |                                    ^
main.c:32:13: note: each undeclared identifier is reported only once for each function it appears in
   32 |         rep(i,26){
      |             ^
main.c:6:36: note: in definition of macro 'rep'
    6 | #define rep(v,e) for(typeof(e) v=0;v<e;++v)
      |                                    ^
main.c: In function 'f1':
main.c:41:13: error: expected ';' before 'i'
   41 |         rep(i,n){
      |             ^
main.c:6:32: note: in definition of macro 'rep'
    6 | #define rep(v,e) for(typeof(e) v=0;v<e;++v)
      |                                ^
main.c:41:13: error: 'i' undeclared (first use in this function)
   41 |         rep(i,n){
      |             ^
main.c:6:36: note: in definition of macro 'rep'
    6 | #define rep(v,e) for(typeof(e) v=0;v<e;++v)
      |                                    ^
main.c:45:17: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
   45 |                 for(int c;c=*rp++,c>='a';){
      |                 ^~~
main.c:45:17: note: use option '-std=c99', '-std=gnu99', '-std=c11' or '-std=gnu11' to compile your code
main.c:49:21: error: expected ';' before 'c'
   49 |                 rep(c,26){
      |                     ^
main.c:6:32: note: in definition of macro 'rep'
    6 | #define rep(v,e) for(typeof(e) v=0;v<e;++v)
      |                                ^
main.c: In function 'f2':
main.c:57:13: error: expected ';' before 'h'
   57 |         rep(h,1<<HASH_BITS){
      |             ^
main.c:6:32:

ソースコード

diff #
raw source code

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

#define rd_init() char*rp=({char*mmap();mmap(0l,1l<<25,1,2,0,0ll);})
#define rd() ({int _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;})
#define rep(v,e) for(typeof(e) v=0;v<e;++v)

#define HASH_BITS 16
#define HASH_MASK ((1<<HASH_BITS)-1)
unsigned hash[1<<HASH_BITS];

int hash_add(unsigned x){
	int h=x&HASH_MASK;
	while(1){
		if(hash[h]==0){
			hash[h]=x;
			return h;
		}
		if(hash[h]==x){
			return h;
		}
		h=h+1&HASH_MASK;
	}
}

int hn[1<<HASH_BITS];
char ss[1000][11];
unsigned ch[26];

void f0(){
	unsigned v=1;
	rep(i,26){
		ch[i]=v;
		v*=257;
	}
}

void f1(){
	rd_init();
	int n=rd();
	rep(i,n){
		char*s=ss[i];
		int j=0;
		unsigned v=0;
		for(int c;c=*rp++,c>='a';){
			s[j++]=c;
			v+=ch[c-'a'];
		}
		rep(c,26){
			int h=hash_add(v+ch[c]);
			hn[h]=hn[h]?-1:i+1;
		}
	}
}

void f2(){
	rep(h,1<<HASH_BITS){
		if(hn[h]>0){
			char wbuf[16];
			memcpy(wbuf,ss[hn[h]-1],11);
			unsigned v=hash[h];
			int j=0;
			for(int c;c=wbuf[j++],c>='a';){
				v-=ch[c-'a'];
			}
			rep(c,26){
				if(ch[c]==v){
					wbuf[j-1]=c+'a';
					write(1,wbuf,j);
					_exit(0);
				}
			}
			_exit(1);
		}
	}
	write(1,"-1",2);
	_exit(0);
}

int main(){
	f0();
	f1();
	f2();
}
0