結果

問題 No.1909 Detect from Substrings
ユーザー 沙耶花沙耶花
提出日時 2022-04-22 21:44:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 1,014 bytes
コンパイル時間 4,341 ms
コンパイル使用メモリ 264,000 KB
実行使用メモリ 13,300 KB
最終ジャッジ日時 2023-09-06 08:05:19
合計ジャッジ時間 8,759 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 16 ms
8,340 KB
testcase_06 AC 30 ms
13,184 KB
testcase_07 AC 30 ms
13,300 KB
testcase_08 AC 90 ms
8,932 KB
testcase_09 AC 91 ms
8,896 KB
testcase_10 AC 54 ms
10,552 KB
testcase_11 AC 54 ms
10,552 KB
testcase_12 AC 40 ms
11,400 KB
testcase_13 AC 90 ms
8,928 KB
testcase_14 AC 90 ms
8,960 KB
testcase_15 AC 90 ms
8,952 KB
testcase_16 AC 40 ms
11,388 KB
testcase_17 AC 29 ms
12,300 KB
testcase_18 AC 30 ms
13,104 KB
testcase_19 AC 29 ms
13,188 KB
testcase_20 AC 30 ms
13,192 KB
testcase_21 AC 91 ms
8,968 KB
testcase_22 AC 90 ms
8,876 KB
testcase_23 AC 54 ms
10,636 KB
testcase_24 AC 55 ms
10,816 KB
testcase_25 AC 40 ms
11,372 KB
testcase_26 AC 90 ms
8,892 KB
testcase_27 AC 90 ms
8,872 KB
testcase_28 AC 91 ms
8,936 KB
testcase_29 AC 89 ms
9,144 KB
testcase_30 AC 92 ms
8,956 KB
testcase_31 AC 92 ms
8,872 KB
testcase_32 AC 91 ms
8,876 KB
testcase_33 AC 88 ms
8,888 KB
testcase_34 AC 91 ms
9,132 KB
testcase_35 AC 87 ms
9,148 KB
testcase_36 AC 91 ms
8,892 KB
testcase_37 AC 90 ms
8,872 KB
testcase_38 AC 90 ms
8,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001



vector<int> get(string s,string t){
	vector<int> ret(s.size()+1,0);
	int c = 0;
	rep(i,s.size()){
		if(s[i] == t[c]){
			c++;
		}
		ret[i+1] = c;
	}
	return ret;
}

int main(){
	
	vector<string> s;
	int ans = 0;
	int n,m;
	cin>>n>>m;
	s.resize(n);
	rep(i,n)cin>>s[i];
	
	vector<vector<int>> x(n-1);
	rep(i,n-1){
		x[i] = get(s[0],s[i+1]);
	}
	rep(i,n)reverse(s[i].begin(),s[i].end());
	vector<vector<int>> y(n-1);
	rep(i,n-1){
		y[i] = get(s[0],s[i+1]);
	}
	rep(i,n)reverse(s[i].begin(),s[i].end());
	rep(i,m+1){
		rep(j,26){
			if(i!=m && s[0][i]=='a'+j)continue;
			bool f = true;
			rep(k,n-1){
				if(x[k][i] + y[k][m-i] < m-1){
					f = false;
					break;
				}
				if(s[k+1][x[k][i]]!='a'+j){
					f = false;
					break;
				}
			}
			if(f)ans++;
			
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}
0