結果

問題 No.3204 Permuted Integer
ユーザー Jikky1618
提出日時 2025-07-19 00:07:10
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 879 bytes
コンパイル時間 3,817 ms
コンパイル使用メモリ 288,448 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-07-19 00:07:17
合計ジャッジ時間 6,302 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

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 = 0; i * i <= 1e9 + 1; i++) {
        vector<int> c(10);
        for (char x : to_string(i * i)) c[x - '0']++;
        if (!mp.contains(c)) mp[c] = i * i;
    }

    auto solve = [&](int N) {
        vector<int> c(10);
        for (char x : to_string(N)) 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