結果

問題 No.1005 BOT対策
ユーザー SSRS
提出日時 2020-11-07 11:24:34
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 650 bytes
コンパイル時間 623 ms
コンパイル使用メモリ 69,964 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-06-20 00:54:57
合計ジャッジ時間 1,421 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
	string S;
	cin >> S;
	string T;
	cin >> T;
	int N = S.size();
	int M = T.size();
	vector<int> p;
	for (int i = 0; i <= N - M; i++){
		bool ok = true;
		for (int j = 0; j < M; j++){
			if (S[i + j] != T[j]){
				ok = false;
			}
		}
		if (ok){
			p.push_back(i);
		}
	}
	if (p.empty()){
		cout << 0 << endl;
	} else {
		if (M == 1){
			cout << -1 << endl;
		} else {
			int cnt = p.size();
			int ans = 0;
			int prev = 0;
			for (int i = 0; i < cnt; i++){
				if (prev <= p[i]){
					prev = p[i] + M - 1;
					ans++;
				}
			}
			cout << ans << endl;
		}
	}
}
0