結果

問題 No.3204 Permuted Integer
ユーザー Jikky1618
提出日時 2025-07-18 23:59:08
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 935 bytes
コンパイル時間 3,606 ms
コンパイル使用メモリ 288,672 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-07-18 23:59:14
合計ジャッジ時間 5,653 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...)
#endif

constexpr int INF = (1 << 30) - 1;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int T;
    cin >> T;

    map<vector<int>, int> mp;
    for (int i = 1; i * i <= 1e9 + 10; i++) {
        string S = to_string(i * i);
        vector<int> c(10);
        for (char x : S) c[x - '0']++;
        mp[c] = i * i;
    }

    auto solve = [&](int N) {
        string S = to_string(N);
        vector<int> c(10);
        for (char x : S) c[x - '0']++;
        int mz = c[0];
        for (int z = 0; z <= mz; z++) {
            c[0] = z;
            if (mp.contains(c)) {
                return mp[c];
            }
        }
        return -1;
    };

    while (T--) {
        int N;
        cin >> N;
        cout << solve(N) << '\n';
    }
}
0