結果

問題 No.3204 Permuted Integer
コンテスト
ユーザー vjudge1
提出日時 2026-05-02 11:11:35
言語 C++23(gnu拡張)
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,094 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,613 ms
コンパイル使用メモリ 348,608 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-02 11:11:45
合計ジャッジ時間 8,502 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

using i32 = int;
using i64 = long long;
#define int i64

vector<int> convert(int n) {
    vector<int> vals;
    while (n) {
        if (n % 10 != 0) {
            vals.push_back(n % 10);
        }
        n /= 10;
    }
    sort(vals.begin(), vals.end());
    return vals;
}

bool compare(vector<int> &first, vector<int> &second) {
    if (first.size() != second.size()) {
        return false;
    }
    for (int i = 0; i < first.size(); i++) {
        if (first[i] != second[i]) {
            return false;
        }
    }
    return true;
}

signed main() {
    map<vector<int>, int> simps;
    vector<int> nums;
    for (int i = 0; i * i <= 1e9; i++) {
        auto result = convert(i * i);
        if (!simps.count(convert(i * i))) {
            simps[result] = i * i;
        }
    }

    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;
        vector<int> voip = convert(n);
        if (simps.count(voip)) {
            cout << simps[voip] << endl;
        } else {
            cout << -1 << endl;
        }
    }
}
0