結果
| 問題 |
No.3204 Permuted Integer
|
| コンテスト | |
| ユーザー |
a01sa01to
|
| 提出日時 | 2025-07-20 00:53:38 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 92 ms / 2,000 ms |
| コード長 | 914 bytes |
| コンパイル時間 | 4,162 ms |
| コンパイル使用メモリ | 283,812 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-07-20 00:53:46 |
| 合計ジャッジ時間 | 6,036 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "settings/debug.cpp"
#else
#define Debug(...) void(0)
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
using arr = array<int, 10>;
map<arr, int> mp;
for (int i = 1; i * i <= 1'000'000'000; ++i) {
int x = i * i;
string s = to_string(x);
arr a = { 0 };
for (char c : s) a[c - '0']++;
if (!mp.contains(a)) mp[a] = x;
}
int q;
cin >> q;
while (q--) {
string s;
cin >> s;
arr a = { 0 };
for (char c : s) a[c - '0']++;
constexpr int INF = 1e9;
int ans = INF;
do {
if (mp.contains(a)) ans = min(ans, mp[a]);
a[0]--;
} while (a[0] >= 0);
if (ans != INF) {
cout << ans << '\n';
}
else {
cout << -1 << '\n';
}
}
return 0;
}
a01sa01to