結果
| 問題 |
No.3204 Permuted Integer
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-07-18 21:51:42 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 203 ms / 2,000 ms |
| コード長 | 867 bytes |
| コンパイル時間 | 1,328 ms |
| コンパイル使用メモリ | 117,432 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-07-18 23:38:43 |
| 合計ジャッジ時間 | 5,572 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 26 |
ソースコード
#include <iostream>
#include <unordered_map>
#include <string>
#include <algorithm>
int main() {
std::unordered_map<std::string, int> roots;
for (int i = 1; i * i <= 1000000000; i++) {
if (i % 10 == 0) continue;
int sq = i * i;
std::string s = std::to_string(sq);
auto t = s;
std::sort(t.rbegin(), t.rend());
if (!roots[t]) roots[t] = sq;
}
int T;
std::cin >> T;
while (T--) {
std::string N;
std::cin >> N;
if (N.size() == 10) {
std::cout << 1 << std::endl;
continue;
}
std::sort(N.rbegin(), N.rend());
int result = -1;
if (roots[N]) result = roots[N];
while (N.back() == '0') {
N.pop_back();
if (roots[N]) result = roots[N];
}
std::cout << result << std::endl;
}
}