結果
| 問題 |
No.3204 Permuted Integer
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-07-19 20:47:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,191 bytes |
| コンパイル時間 | 2,060 ms |
| コンパイル使用メモリ | 200,764 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-07-19 20:47:16 |
| 合計ジャッジ時間 | 4,191 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | AC * 8 WA * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
constexpr int r = 32000;
vector<pair<ll,int>> a(r + 1);
array<int, 10> cnt{};
for(int i = 1; i <= r; i++){
cnt.fill(0);
int v = i * i;
while(v){
int d = v / 10;
cnt[v - d * 10]++;
v = d;
}
for(int j = 9; j >= 0; j--) a[i].first = a[i].first * 10 + cnt[j];
a[i].second = i * i;
}
sort(a.begin(), a.end());
int T, v;
cin >> T;
while(T--){
cin >> v;
ll hs = 0;
cnt.fill(0);
while(v){
int d = v / 10;
cnt[v - d * 10]++;
v = d;
}
for(int i = 9; i >= 0; i--) hs = hs * 10 + cnt[i];
int ans = -1;
while(ans == -1){
int p = lower_bound(a.begin(), a.end(), make_pair(hs, -1)) - a.begin();
if(p == a.size() || a[p].first != hs){
if(hs % 10 == 0) break;
hs--;
continue;
}
ans = a[p].second;
break;
}
cout << ans << '\n';
}
}