結果

問題 No.3204 Permuted Integer
ユーザー iastm
提出日時 2025-07-18 21:47:40
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 874 bytes
コンパイル時間 1,444 ms
コンパイル使用メモリ 117,204 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-07-18 21:47:45
合計ジャッジ時間 5,445 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other AC * 7 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#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());
        roots[t] = sq;
        int max = t.size();
        for (int j = 1; max + j <= 9; j++) {
            t.push_back('0');
            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());
        if (roots[N]) std::cout << roots[N] << std::endl;
        else std::cout << -1 << std::endl;
    }
}
0