結果

問題 No.3204 Permuted Integer
ユーザー nono00
提出日時 2025-07-27 23:08:11
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 1,723 bytes
コンパイル時間 3,461 ms
コンパイル使用メモリ 285,736 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2025-07-27 23:08:21
合計ジャッジ時間 8,766 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, vector<T>, greater<T>>;
#define rep2(i, n) for (ll i = 0; i < (n); i++)
#define rep3(i, l, r) for (ll i = (l); i < (r); i++)
#define rrep2(i, n) for (ll i = n; i-- > 0;)
#define rrep3(i, r, l) for (ll i = (r); i-- > (l);)
#define overload(a, b, c, d, ...) d
#define rep(...) overload(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rrep(...) overload(__VA_ARGS__, rrep3, rrep2)(__VA_ARGS__)
#define all(x) begin(x), end(x)
bool chmin(auto& lhs, auto rhs) {
    return lhs > rhs ? lhs = rhs, 1 : 0;
}
bool chmax(auto& lhs, auto rhs) {
    return lhs < rhs ? lhs = rhs, 1 : 0;
}
struct IOIO {
    IOIO() {
        std::cin.tie(0)->sync_with_stdio(0);
    }
} ioio;

void solve() {
    map<vector<int>, ll> mp;
    for (ll i = 0; i <= 100000; i++) {
        ll v = i * i;
        auto s = to_string(i * i);
        vector<int> freq(10);
        for (auto c: s) freq[c - '0']++;
        if (mp.contains(freq)) {
            chmin(mp[freq], v);
        } else {
            mp[freq] = v;
        }
    }
    int t;
    cin >> t;
    constexpr ll inf = 1e18;
    while (t--) {
        string s;
        cin >> s;
        vector<int> freq(10);
        for (auto c: s) freq[c - '0']++;
        ll ans = inf;
        while (freq[0] >= 0) {
            if (mp.contains(freq)) {
                chmin(ans, mp[freq]);
            }
            freq[0]--;
        }
        cout << (ans == inf ? -1 : ans) << '\n';
    }
}

int main() {
    int t = 1;
    //  cin >> t;
    while (t--) solve();
}
0