結果
| 問題 | No.3204 Permuted Integer |
| コンテスト | |
| ユーザー |
Iroha_3856
|
| 提出日時 | 2025-07-18 21:33:17 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 298 ms / 2,000 ms |
| コード長 | 1,553 bytes |
| 記録 | |
| コンパイル時間 | 2,926 ms |
| コンパイル使用メモリ | 285,804 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-07-18 23:36:52 |
| 合計ジャッジ時間 | 9,102 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 26 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for (int i = (int)(l); i<(int)(r); i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define siz(x) (int)(x).size()
const int inf = 1e9;
const ll INF = 4e18;
template<class T>bool chmax(T &a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, T b) { if (b<a) { a=b; return 1; } return 0; }
vector<int> di = {-1, 0, 1, 0}, dj = {0, -1, 0, 1};
void solve() {
int T; cin >> T;
map<array<int, 10>, ll> mp;
for (ll x = 1; x * x <= 1e10; x++) {
ll t = x * x;
string s = to_string(t);
array<int, 10> cnt;
rep(i, 0, 10) cnt[i] = 0;
for (char c : s) {
cnt[c-'0']++;
}
if (!mp.contains(cnt)) {
mp[cnt] = x * x;
}
}
// cout << "ok" << endl;
while(T--) {
string N; cin >> N;
array<int, 10> cnt;
rep(i, 0, 10) cnt[i] = 0;
for (char c : N) {
cnt[c-'0']++;
}
// rep(i, 0, 10) cout << cnt[i] << " ";
// cout << endl;
//0の個数を全探索
ll ans = INF;
rep(x, 0, 11) {
if (mp.contains(cnt)) {
chmin(ans, mp[cnt]);
}
cnt[0]--;
}
if (ans == INF) ans = -1;
cout << ans << endl;
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int T = 1;
// cin >> T;
while(T--) {
solve();
}
}
Iroha_3856