結果

問題 No.430 文字列検索
ユーザー ikdikd
提出日時 2016-10-03 11:50:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 806 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 80,228 KB
実行使用メモリ 6,612 KB
最終ジャッジ日時 2023-08-15 17:34:31
合計ジャッジ時間 2,236 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 141 ms
6,612 KB
testcase_02 AC 9 ms
4,376 KB
testcase_03 AC 9 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 140 ms
6,324 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 9 ms
4,376 KB
testcase_11 AC 54 ms
5,496 KB
testcase_12 AC 54 ms
5,804 KB
testcase_13 AC 54 ms
5,872 KB
testcase_14 AC 41 ms
4,880 KB
testcase_15 AC 31 ms
4,380 KB
testcase_16 AC 11 ms
4,376 KB
testcase_17 AC 10 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include<map>
using namespace std;

#define int long long

int powpow(int a, int b){
	
	int ret=1;
	for(int i=0; i<b; i++){
		ret*=a;
	}
	
	return ret;
}

int calc(string t){
	
	int ret=0;
	for(int i=0; i<t.size(); i++){
			ret+=(t[i]-'A')*powpow(26, i);
	}
	
	return ret;
}

signed main() {
	
	string S;
	cin>> S;
	int M;
	cin>> M;
	string C[M];
	for(int i=0; i<M; i++) cin>> C[i];
	
	int ans=0;
	for(int len=1; len<=10; len++){
		if(S.size()<len) continue;
		int ha=calc(S.substr(0, len));
		map<int, int> memo;
		for(int k=0; k<S.size()-len; k++){
			memo[ha]++;
			ha-=S[k]-'A';
			ha/=26;
			ha+=(S[k+len]-'A')*powpow(26, len-1);
		}
		memo[ha]++;
		
		for(int k=0; k<M; k++){
			if(C[k].size()!=len) continue;
			ans+=memo[calc(C[k])];
		}
	}
	
	cout<< ans<< endl;
	
	return 0; 
}
0