結果

問題 No.430 文字列検索
ユーザー ikdikd
提出日時 2016-10-03 11:50:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 806 bytes
コンパイル時間 867 ms
コンパイル使用メモリ 80,608 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-03 04:29:16
合計ジャッジ時間 2,109 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 143 ms
6,940 KB
testcase_02 AC 10 ms
6,944 KB
testcase_03 AC 10 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 137 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 10 ms
6,940 KB
testcase_11 AC 54 ms
6,944 KB
testcase_12 AC 54 ms
6,940 KB
testcase_13 AC 55 ms
6,940 KB
testcase_14 AC 41 ms
6,940 KB
testcase_15 AC 31 ms
6,940 KB
testcase_16 AC 12 ms
6,940 KB
testcase_17 AC 11 ms
6,944 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