結果

問題 No.3204 Permuted Integer
コンテスト
ユーザー vjudge1
提出日時 2026-05-02 11:07:24
言語 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
結果
TLE  
実行時間 -
コード長 1,202 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,664 ms
コンパイル使用メモリ 342,536 KB
実行使用メモリ 13,920 KB
最終ジャッジ日時 2026-05-02 11:07:49
合計ジャッジ時間 6,665 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other TLE * 1 -- * 25
権限があれば一括ダウンロードができます

ソースコード

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() {
    vector<vector<int>> simps;
    vector<int> nums;
    for (int i = 0; i * i <= 1e9; i++) {
        simps.emplace_back(convert(i * i));
        nums.push_back(i * i);
    }

    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;
        vector<int> voip = convert(n);
        int result = INT64_MAX;

        for (int i = 0; i < nums.size(); i++) {
            if (compare(voip, simps[i])) {
                result = min(nums[i], result);
            }
        }
        if (result == INT64_MAX) {
            result = -1;
        }
        cout << result << endl;
    }
}
0