結果
| 問題 |
No.3204 Permuted Integer
|
| コンテスト | |
| ユーザー |
aqua
|
| 提出日時 | 2025-07-18 22:49:28 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 216 ms / 2,000 ms |
| コード長 | 903 bytes |
| コンパイル時間 | 3,501 ms |
| コンパイル使用メモリ | 286,688 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-07-18 23:40:37 |
| 合計ジャッジ時間 | 8,018 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool chmin(auto &a, auto b) { return a > b ? a = b, true : false; }
bool chmax(auto &a, auto b) { return a < b ? a = b, true : false; }
void solve(map<string, int> &mp) {
string N; cin >> N;
int ans = 2'000'000'000;
sort(N.begin(), N.end(), greater());
while(N.size() > 0) {
if(mp.count(N)) chmin(ans, mp[N]);
if(N.back() == '0') N.pop_back();
else break;
}
if(ans == 2'000'000'000) cout << -1 << endl;
else cout << ans << endl;
return;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
map<string, int> mp;
for(int i=1; i*i<=1'000'000'000; ++i) {
int y = i*i;
string x = to_string(y);
sort(x.begin(), x.end(), greater());
if(!mp.count(x)) mp[x] = y;
}
int T; cin >> T;
for(int i=0; i<T; ++i) solve(mp);
}
aqua