結果
| 問題 |
No.2715 Unique Chimatagram
|
| コンテスト | |
| ユーザー |
Tatsu_mr
|
| 提出日時 | 2024-04-05 22:09:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,434 bytes |
| コンパイル時間 | 2,899 ms |
| コンパイル使用メモリ | 211,568 KB |
| 最終ジャッジ日時 | 2025-02-20 21:25:35 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 WA * 3 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
vector<string> t = s;
for (int i = 0; i < n; i++) {
sort(t[i].begin(), t[i].end());
}
sort(t.begin(), t.end());
t.erase(unique(t.begin(), t.end()), t.end());
if (t.size() == 1) {
cout << -1 << endl;
return 0;
}
vector<vector<int>> cnt(n, vector<int>(26));
for (int i = 0; i < n; i++) {
for (char c : s[i]) {
cnt[i][c - 'a']++;
}
}
for (int i = 0; i < n; i++) {
for (char c = 'a'; c <= 'z'; c++) {
cnt[i][c - 'a']++;
bool ok = true;
for (int ni = 0; ni < n; ni++) {
if (i == ni) {
continue;
}
int zero = 0, one = 0;
for (int j = 0; j < 26; j++) {
if (cnt[i][j] == cnt[ni][j]) {
zero++;
}
if (cnt[i][j] - cnt[ni][j] == 1) {
one++;
}
}
if (zero == 25 && one == 1) {
ok = false;
}
}
if (ok) {
cout << s[i] + c << endl;
return 0;
}
cnt[i][c - 'a']--;
}
}
}
Tatsu_mr