結果

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <unordered_map>
string cnt_kazus(int n) {
    string cnt(10, '0');
    while (n) {
        cnt[n % 10]++;
        if (n%10 == 0){
            cnt[0]--;
        }
        n /= 10;
    }
    return cnt;
}

int main(){
    int T; cin >> T;
    unordered_map<string, int> mins;

    for (int i = 0;; i++) {
        int crr = 1LL * i * i;
        if (crr > 1e9) break;
        string cnt = cnt_kazus(crr);
        if (mins.count(cnt)) {
            mins[cnt] = min(mins[cnt], crr);
        } else {
            mins[cnt] = crr;
        }
    }

    while (T--) {
        int N; cin >> N;
        string cnt = cnt_kazus(N);
        if (mins.count(cnt)) {
            cout << mins[cnt] << endl;
        } else {
            cout << -1 << endl;
        }
    }
}
0