結果
問題 |
No.3204 Permuted Integer
|
ユーザー |
|
提出日時 | 2025-09-18 11:08:43 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 119 ms / 2,000 ms |
コード長 | 876 bytes |
コンパイル時間 | 5,609 ms |
コンパイル使用メモリ | 335,540 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-09-18 11:08:53 |
合計ジャッジ時間 | 9,501 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; const ll MOD = 998244353; #include<atcoder/all> using namespace atcoder; using mint = modint998244353; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll t;cin>>t; map<vector<ll>,ll> mp; ll cnt=1; while(cnt*cnt<=1e9+1){ ll cnt2=cnt*cnt; string s=to_string(cnt2); vector<ll> tmp(10,0); for(auto c:s) tmp[c-'0']++; if(!mp.count(tmp)) mp[tmp]=cnt2; cnt++; } while(t--){ string n;cin>>n; vector<ll> tmp(10,0); for(auto c:n) tmp[c-'0']++; ll ans=LLONG_MAX; ll q=tmp[0]; rep(i,q+1){ if(mp.count(tmp)){ ans=min(ans,mp[tmp]); } tmp[0]--; } if(ans==LLONG_MAX) cout<<-1<<"\n"; else cout<<ans<<"\n"; } }