結果
問題 |
No.3204 Permuted Integer
|
ユーザー |
![]() |
提出日時 | 2025-07-23 14:45:09 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 764 bytes |
コンパイル時間 | 2,211 ms |
コンパイル使用メモリ | 178,720 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2025-07-23 14:45:19 |
合計ジャッジ時間 | 10,635 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; map<string, 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>()); mp[s].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>()); ll inf = 1e10; ll a = inf, b = inf; if(mp.count(s)) a = mp[s][0]; while(s.back() == '0') s.pop_back(); if(mp.count(s)) b = mp[s][0]; if(a != inf || b != inf) cout << min(a, b) << endl; else cout << -1 << endl; } }