結果
問題 |
No.3204 Permuted Integer
|
ユーザー |
![]() |
提出日時 | 2025-07-23 15:54:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 288 ms / 2,000 ms |
コード長 | 709 bytes |
コンパイル時間 | 1,816 ms |
コンパイル使用メモリ | 173,396 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-07-23 15:54:32 |
合計ジャッジ時間 | 7,848 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 26 |
ソースコード
#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; ll n = 1e9; map<vector<int>, int> mp; for(ll i = 1; i * i <= n; i++) { int sq = i * i; vector<int> c(10); int m = sq; while(m) { int d = m % 10; c[d]++; m /= 10; } if(mp.count(c)) mp[c] = min(mp[c], sq); else mp[c] = sq; } rep(ti, 0, T) { int N; cin >> N; int INF = 1e9 + 1; vector<int> c(10); while(N) { int d = N % 10; c[d]++; N /= 10; } int ans = INF; int r = c[0] + 1; rep(i, 0, r) { if(mp.count(c)) ans = min(ans, mp[c]); c[0]--; } if(ans == INF) ans = -1; cout << ans << endl; } }