結果

問題 No.2715 Unique Chimatagram
ユーザー tailstails
提出日時 2024-04-05 23:41:59
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,193 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 25,088 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-04-05 23:42:02
合計ジャッジ時間 2,222 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 1 ms
6,548 KB
testcase_04 AC 1 ms
6,548 KB
testcase_05 AC 1 ms
6,548 KB
testcase_06 AC 1 ms
6,548 KB
testcase_07 AC 1 ms
6,548 KB
testcase_08 AC 1 ms
6,548 KB
testcase_09 AC 1 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 1 ms
6,548 KB
testcase_13 AC 1 ms
6,548 KB
testcase_14 AC 2 ms
6,548 KB
testcase_15 AC 1 ms
6,548 KB
testcase_16 AC 1 ms
6,548 KB
testcase_17 AC 1 ms
6,548 KB
testcase_18 AC 1 ms
6,548 KB
testcase_19 AC 2 ms
6,548 KB
testcase_20 AC 2 ms
6,548 KB
testcase_21 AC 1 ms
6,548 KB
testcase_22 AC 1 ms
6,548 KB
testcase_23 AC 2 ms
6,548 KB
testcase_24 AC 2 ms
6,548 KB
testcase_25 AC 2 ms
6,548 KB
testcase_26 AC 2 ms
6,548 KB
testcase_27 AC 1 ms
6,548 KB
testcase_28 AC 1 ms
6,548 KB
testcase_29 AC 2 ms
6,548 KB
testcase_30 AC 1 ms
6,548 KB
testcase_31 AC 2 ms
6,548 KB
testcase_32 AC 1 ms
6,548 KB
testcase_33 AC 1 ms
6,548 KB
testcase_34 AC 1 ms
6,548 KB
testcase_35 AC 1 ms
6,548 KB
testcase_36 AC 1 ms
6,548 KB
testcase_37 AC 1 ms
6,548 KB
testcase_38 AC 2 ms
6,548 KB
testcase_39 AC 2 ms
6,548 KB
testcase_40 AC 1 ms
6,548 KB
testcase_41 AC 1 ms
6,548 KB
testcase_42 AC 1 ms
6,548 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘f2’:
main.c:68:41: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
   68 |                                         write(1,s,j);
      |                                         ^~~~~
main.c:69:41: warning: implicit declaration of function ‘_exit’ [-Wimplicit-function-declaration]
   69 |                                         _exit(0);
      |                                         ^~~~~
main.c:69:41: warning: incompatible implicit declaration of built-in function ‘_exit’ [-Wbuiltin-declaration-mismatch]
main.c:72:25: warning: incompatible implicit declaration of built-in function ‘_exit’ [-Wbuiltin-declaration-mismatch]
   72 |                         _exit(1);
      |                         ^~~~~
main.c:76:9: warning: incompatible implicit declaration of built-in function ‘_exit’ [-Wbuiltin-declaration-mismatch]
   76 |         _exit(0);
      |         ^~~~~

ソースコード

diff #

#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*=12347;
	}
}

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*s=ss[hn[h]-1];
			unsigned v=hash[h];
			int j=0;
			for(int c;c=s[j++],c>='a';){
				v-=ch[c-'a'];
			}
			rep(c,26){
				if(ch[c]==v){
					s[j-1]=c+'a';
					write(1,s,j);
					_exit(0);
				}
			}
			_exit(1);
		}
	}
	write(1,"-1",2);
	_exit(0);
}

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