結果
| 問題 | No.517 壊れたアクセサリー |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-26 13:05:58 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,393 bytes |
| 記録 | |
| コンパイル時間 | 1,245 ms |
| コンパイル使用メモリ | 86,400 KB |
| 実行使用メモリ | 15,940 KB |
| 最終ジャッジ日時 | 2025-09-26 13:06:06 |
| 合計ジャッジ時間 | 8,603 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 9 TLE * 2 -- * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:16:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
16 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:24:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
24 | scanf("%d", &m);
| ~~~~~^~~~~~~~~~
ソースコード
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 27;
int n, m, l, pos[N], cnt;
bool used[N];
string s, a, ans;
vector<string> sa, sb;
int main() {
scanf("%d", &n);
sa.reserve(n);
l = 0;
for (int i = 0; i < n; ++i) {
cin >> s;
sa.push_back(s);
l += s.size();
}
scanf("%d", &m);
sb.reserve(m);
for (int i = 0; i < m; ++i) {
cin >> s;
sb.push_back(s);
}
sort(sa.begin(), sa.end());
a.resize(l);
cnt = 0;
do {
for (int i = 0, idx = 0; i < n; ++i) {
for (int j = 0; j < sa[i].size(); ++j) {
pos[sa[i][j] - 'A' + 1] = idx;
a[idx++] = sa[i][j];
}
}
memset(used, 0, sizeof(used));
bool ok = true;
for (int i = 0; i < m && ok; ++i) {
for (int j = 0; j < sb[i].size(); ++j) {
int v = pos[sb[i][0] - 'A' + 1] + j;
if (v >= l || used[v]) {
ok = false;
break;
}
used[v] = true;
}
}
if (ok) {
++cnt;
ans = a;
if (cnt > 1) break;
}
} while (next_permutation(sa.begin(), sa.end()));
if (cnt == 1) puts(ans.c_str());
else puts("-1");
return 0;
}