結果

問題 No.962 LCPs
ユーザー polylogK
提出日時 2019-12-18 00:33:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,073 bytes
コンパイル時間 1,590 ms
コンパイル使用メモリ 168,368 KB
実行使用メモリ 16,408 KB
最終ジャッジ日時 2024-09-14 01:59:31
合計ジャッジ時間 6,135 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other WA * 15 TLE * 1 -- * 48
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

#define NDEBUG

int main() {
	int n, k; scanf("%d%d", &n, &k);
	std::vector<std::string> s(n);
	for(int i = 0; i < n; i++) cin >> s[i];
	
	// pre
	auto calc_LCP = [&](int L, int R) -> int {
		int tmp = s[L].size();
		for(int i = L; i < R - 1; i++) {
			int bound = std::min(tmp, (int)s[i + 1].size());

			tmp = 0;
			for(int j = 0; j < bound; j++) {
				if(s[i][j] != s[i + 1][j]) break;

				tmp = j + 1;
			}
		}
		return tmp;
	};
	
	// solve
	i64 ans = 0;
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j <= n; j++) {
			if(calc_LCP(i, j) < k) continue;
			ans++;
			
			#ifndef NDEBUG
			fprintf(stderr, "[%d, %d)\n", i + 1, j + 1);
			#endif
		}
	}
	printf("%lld\n", ans);
	return 0;
}
0