結果

問題 No.430 文字列検索
ユーザー ikdikd
提出日時 2016-10-03 11:38:59
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 777 bytes
コンパイル時間 674 ms
コンパイル使用メモリ 72,444 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 11:15:50
合計ジャッジ時間 2,473 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 132 ms
6,944 KB
testcase_02 AC 8 ms
6,940 KB
testcase_03 AC 9 ms
6,940 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 126 ms
6,940 KB
testcase_09 RE -
testcase_10 AC 9 ms
6,940 KB
testcase_11 AC 48 ms
6,944 KB
testcase_12 AC 47 ms
6,940 KB
testcase_13 AC 47 ms
6,940 KB
testcase_14 AC 37 ms
6,940 KB
testcase_15 AC 27 ms
6,944 KB
testcase_16 AC 10 ms
6,944 KB
testcase_17 AC 9 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++){
		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