結果
| 問題 |
No.517 壊れたアクセサリー
|
| コンテスト | |
| ユーザー |
Bwambocos
|
| 提出日時 | 2017-05-28 21:58:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,917 bytes |
| コンパイル時間 | 1,605 ms |
| コンパイル使用メモリ | 172,448 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-21 15:25:21 |
| 合計ジャッジ時間 | 2,271 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 2 |
| other | AC * 3 WA * 12 |
ソースコード
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;
int N, M;
std::string A[30], B[30];
std::string ans;
int main()
{
in >> N;
rep(i, N) { in >> A[i]; }
in >> M;
rep(i, M) { in >> B[i]; }
ans = A[0];
while (true)
{
bool ok = false;
rep(i, N)
{
rep(j, A[i].length())
{
if (A[i][j] == ans[ans.length() - 1])
{
bool flag = true;
int cou = 0;
rep(k, j)
{
if (ans[ans.length() - j - 1 + k] != A[i][k])
{
flag = false;
break;
}
}
if (flag)
{
ok = true;
ans = ans.substr(0, ans.length() - (j + 1)) + A[i];
A[i].erase();
}
}
if (A[i][j] == ans[0])
{
bool flag = true;
int cou = 0;
for (int k = j; k < std::min(ans.length(), A[i].length()); ++k)
{
if (ans[k] != A[i][k])
{
flag = false;
break;
}
}
if (flag)
{
ok = true;
ans = A[i].substr(0, j) + ans;
A[i].erase();
}
}
}
rep(j, B[i].length())
{
if (B[i][j] == ans[ans.length() - 1])
{
bool flag = true;
int cou = 0;
rep(k, j)
{
if (ans[ans.length() - j - 1 + k] != B[i][k])
{
flag = false;
break;
}
}
if (flag)
{
ok = true;
ans = ans.substr(0, ans.length() - (j + 1)) + B[i];
B[i].erase();
}
}
if (B[i][j] == ans[0])
{
bool flag = true;
int cou = 0;
for (int k = j; k < std::min(ans.length(), B[i].length()); ++k)
{
if (ans[k] != B[i][k])
{
flag = false;
break;
}
}
if (flag)
{
ok = true;
ans = B[i].substr(0, j) + ans;
B[i].erase();
}
}
}
}
if (!ok) { break; }
}
out << ans << std::endl;
return 0;
}
Bwambocos