結果
| 問題 |
No.3365 Prefix and Suffix X
|
| コンテスト | |
| ユーザー |
テナガザル
|
| 提出日時 | 2025-11-17 23:12:03 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,193 bytes |
| コンパイル時間 | 1,152 ms |
| コンパイル使用メモリ | 104,932 KB |
| 実行使用メモリ | 7,852 KB |
| 最終ジャッジ日時 | 2025-11-17 23:12:17 |
| 合計ジャッジ時間 | 12,998 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | WA * 30 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void solve()
{
string x;
int m;
cin >> x >> m;
int siz = x.size();
for (int i = siz; i <= 18; ++i)
{
string ans(i, '#');
for (int j = 0; j < siz; ++j)
{
ans[j] = x[j];
ans[i - siz + j] = x[j];
}
if (ans.substr(0, siz) != x || ans.substr(i - siz, siz) != x) continue;
long long d = 0;
for (auto c : ans) d = (d * 10LL + (c == '#' ? 0 : c - '0')) % m;
d = (m - d) % m;
if (d == 0)
{
for (auto &c : ans) if (c == '#') c = '0';
cout << ans << endl;
return;
}
int flag = 0;
for (int j = 0; j < 1000; ++j)
{
long long tmp = j * m + d;
if (tmp % 1000 == 0)
{
tmp /= 1000;
for (int k = i - 4; k >= 0 && tmp > 0; --k)
{
ans[k] = tmp % 10;
tmp /= 10;
}
break;
}
}
for (auto c : ans) if (c == '#') flag = 1;
if (ans.substr(0, siz) != x || ans.substr(i - siz, siz) != x) flag = 1;
if (flag) continue;
cout << ans << endl;
return;
}
cout << -1 << endl;
}
int main()
{
int t;
cin >> t;
while (t--) solve();
}
テナガザル