結果

問題 No.2715 Unique Chimatagram
ユーザー ecotteaecottea
提出日時 2024-02-07 23:18:58
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 921 bytes
コンパイル時間 2,075 ms
コンパイル使用メモリ 214,232 KB
実行使用メモリ 5,632 KB
最終ジャッジ日時 2024-09-28 12:48:54
合計ジャッジ時間 3,734 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>
using namespace std;


int main() {
	int n;
	cin >> n;
	assert(1 <= n && n <= (int)1e3);

	vector<string> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];

		int L = (int)s[i].size();
		assert(1 <= L && L <= 10);

		for (auto c : s[i]) {
			assert(islower(c));
		}
	}
	
	// cnt[t] : t が s[i] のチマタグラムとなるような i の個数
	map<string, int> cnt;

	// s[i] と,それに追加する文字 c を全探索する.
	for (int i = 0; i < n; i++) {
		for (char c = 'a'; c <= 'z'; c++) {
			string t = s[i] + c;
			sort(t.begin(), t.end());
			cnt[t]++;
		}
	}

	// ちょうど 1 つの s[i] のチマタグラムとなるような t が見つかれば出力して終了する.
	for (auto& [t, c] : cnt) {
		if (c == 1) {
			cout << t << endl;
			return 0;
		}
	}

	// 見つからなければ -1 を出力する.
	cout << -1 << endl;
}
0