結果

問題 No.1994 Confusing Name
ユーザー MasKoaTSMasKoaTS
提出日時 2022-03-30 20:58:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 507 ms / 2,000 ms
コード長 1,242 bytes
コンパイル時間 814 ms
コンパイル使用メモリ 81,932 KB
実行使用メモリ 255,488 KB
最終ジャッジ日時 2024-04-27 10:26:07
合計ジャッジ時間 8,215 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 5 ms
6,940 KB
testcase_06 AC 9 ms
7,808 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 7 ms
6,940 KB
testcase_09 AC 9 ms
8,320 KB
testcase_10 AC 5 ms
6,944 KB
testcase_11 AC 5 ms
6,940 KB
testcase_12 AC 327 ms
138,112 KB
testcase_13 AC 413 ms
233,216 KB
testcase_14 AC 476 ms
255,488 KB
testcase_15 AC 396 ms
216,064 KB
testcase_16 AC 354 ms
190,848 KB
testcase_17 AC 392 ms
210,560 KB
testcase_18 AC 501 ms
245,248 KB
testcase_19 AC 507 ms
247,296 KB
testcase_20 AC 506 ms
250,112 KB
testcase_21 AC 89 ms
45,824 KB
testcase_22 AC 41 ms
23,296 KB
testcase_23 AC 405 ms
194,048 KB
testcase_24 AC 389 ms
175,488 KB
testcase_25 AC 248 ms
119,552 KB
testcase_26 AC 125 ms
64,128 KB
testcase_27 AC 359 ms
166,144 KB
testcase_28 AC 273 ms
132,864 KB
testcase_29 AC 39 ms
24,064 KB
testcase_30 AC 285 ms
138,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#define rep(i, l, n) for (int i = (l); i < (n); i++)
using namespace std;
using str = string;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T> >;


struct Node {
	int num = 0;
	Node* next[27] = { NULL };
};

struct Trie {
	Node* root = new Node;

	void add(V<int>& lis) {
		Node* last = root;
		for (auto i : lis) {
			if (last->next[i] == NULL) {
				last->next[i] = new Node;
			}
			last = last->next[i];
		}
		(last->num)++;
	}

	int search(V<int>& lis) {
		Node* last = root;
		for (auto i : lis) {
			if (last->next[i] == NULL) {
				return 0;
			}
			last = last->next[i];
		}
		return last->num;
	}
};


int main(void) {
	int n;	cin >> n;
	V<str> s(n);
	VV<int> lis(n, V<int>({}));
	Trie trie;
	rep(i, 0, n) {
		cin >> s[i];
		for (auto c : s[i]) {
			lis[i].push_back(c - 'a');
		}
		V<int> cl = lis[i];
		cl[0] = 26;
		trie.add(cl);
		rep(j, 1, cl.size()) {
			cl[j - 1] = lis[i][j - 1];
			cl[j] = 26;
			trie.add(cl);
		}
	}

	for (auto l : lis) {
		V<int> cl = l;
		int ans = 0;
		cl[0] = 26;
		ans += trie.search(cl) - 1;
		rep(j, 1, cl.size()) {
			cl[j - 1] = l[j - 1];
			cl[j] = 26;
			ans += trie.search(cl) - 1;
		}
		cout << ans << endl;
	}

	return 0;
}
0