結果

問題 No.3204 Permuted Integer
ユーザー tau0529
提出日時 2025-07-18 21:58:15
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 859 ms / 2,000 ms
コード長 1,520 bytes
コンパイル時間 3,483 ms
コンパイル使用メモリ 289,324 KB
実行使用メモリ 17,152 KB
最終ジャッジ日時 2025-07-18 23:39:33
合計ジャッジ時間 24,244 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

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

/*
ショトカ登録
cin cout endl return
int double string char
pair make_pair first second tuple make_tuple
sort erase swap
stoi to_string
auto bool true false
vector queue priority_queue front pop_frpnt
size substr push_back pop_back push pop top
if for while break continue next_permutation
__builtin_popcount 
*/

//無限
int inf = 1020304050;
int64_t INF = 1020304050607080900;

//モッド
int64_t mod = 998244353;

//all マクロ
#define all(v) v.begin(), v.end()


int main () {
    //少数以下
    cout << fixed << setprecision(15);

    map<vector<int64_t>, pair<int64_t, int64_t>> M;
    for (int64_t i = 1; i < 1000000; i++) {
        vector<int64_t> l(9, 0);
        int c0 = 0;
        int64_t j = i * i;
        string s = to_string(j);
        for (auto x : s) {
            int64_t k = x - '0';
            if (k == 0) c0++;
            else l[k - 1]++;
        }
        if (M.count(l) == 0) {
            M[l] = make_pair(c0, j);
        }
    }

    int64_t TT; cin >> TT;
    for (int64_t tt = 0; tt < TT; tt++) {
        int64_t N; cin >> N;
        string S = to_string(N);
        vector<int64_t> L(9, 0);
        int C0 = 0;
        for (auto x : S) {
            int64_t k = x - '0';
            if (k == 0) C0++;
            else L[k - 1]++;
        }
        if (M.count(L) == 0) cout << -1 << endl;
        else {
            if (M.at(L).first <= C0) cout << M.at(L).second << endl;
            else cout << -1 << endl;
        }
    }
}
0