結果
| 問題 |
No.3204 Permuted Integer
|
| コンテスト | |
| ユーザー |
forest3
|
| 提出日時 | 2025-07-23 15:10:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 870 bytes |
| コンパイル時間 | 2,005 ms |
| コンパイル使用メモリ | 181,548 KB |
| 実行使用メモリ | 11,648 KB |
| 最終ジャッジ日時 | 2025-07-23 15:10:47 |
| 合計ジャッジ時間 | 9,779 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 6 WA * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, n) for(int i = a; i < n; i++)
int main() {
int T;
cin >> T;
using P = pair<string, int>;
map<P, vector<int>> mp;
ll n = 1e10;
for(ll i = 1; i * i < n; i++) {
int sq = i * i;
string s = to_string(sq);
sort(s.begin(), s.end(), greater<char>());
int z = 0;
while(s.back() == '0') {
z++;
s.pop_back();
}
mp[P(s, z)].push_back(sq);
}
for(auto it = mp.begin(); it != mp.end(); it++) {
sort(it->second.begin(), it->second.end());
}
rep(ti, 0, T) {
string s;
cin >> s;
sort(s.begin(), s.end(), greater<char>());
int z = 0;
while(s.back() == '0') {
z++;
s.pop_back();
}
int f = 0;
rep(i, 0, z + 1) {
if(mp.count(P(s, i))) {
cout << mp[P(s, i)][0] << endl;
f = 1;
break;
}
}
if(f == 0) cout << -1 << endl;
}
}
forest3