結果
| 問題 | No.3204 Permuted Integer |
| コンテスト | |
| ユーザー |
ゼリトキ
|
| 提出日時 | 2025-07-18 21:56:40 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 80 ms / 2,000 ms |
| コード長 | 944 bytes |
| 記録 | |
| コンパイル時間 | 3,442 ms |
| コンパイル使用メモリ | 289,652 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-07-18 23:39:05 |
| 合計ジャッジ時間 | 5,636 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 ll long long
const long long mod=998244353;
const long long hmod=46216567629137;
int main(){
cin.tie(0)->sync_with_stdio(0);
cout.tie(0);
int T;
cin>>T;
map<ll,ll>dat;
for(ll i=1;i*i<=1000000000;i++){
ll now=i*i;
string s=to_string(now);
sort(s.rbegin(),s.rend());
ll a=stoll(s);
if(dat.count(a)==0) dat[a]=now;
else dat[a]=min(dat[a],now);
}
for(int z=1;z<=T;z++){
ll N;
cin>>N;
string s=to_string(N);
sort(s.rbegin(),s.rend());
ll a=stoll(s);
ll ans=2e18;
while(a%10==0){
if(dat.count(a)){
ans=min(ans,dat[a]);
}
a/=10;
}
if(dat.count(a)) ans=min(ans,dat[a]);
if(ans==2e18) cout<<"-1\n";
else cout<<ans<<"\n";
}
}
ゼリトキ