結果
問題 |
No.3204 Permuted Integer
|
ユーザー |
|
提出日時 | 2025-07-18 21:58:15 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 238 ms / 2,000 ms |
コード長 | 1,003 bytes |
コンパイル時間 | 3,797 ms |
コンパイル使用メモリ | 295,844 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-07-18 23:39:14 |
合計ジャッジ時間 | 8,419 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { map<int, vector<int>> mp; for (int i = 1; i * i <= 1e9; i++) { string s = to_string(i * i); sort(s.begin(), s.end()); mp[stoi(s)].push_back(i * i); if (stoi(s) < 0) { cout << s << endl; } } int T; cin >> T; while (T--) { int N; cin >> N; string s = to_string(N); sort(s.rbegin(), s.rend()); int cnt = 0; while (s.back() == '0') { s.pop_back(); cnt++; } reverse(s.begin(), s.end()); if (mp.contains(stoi(s))) { int ans = *min_element(mp[stoi(s)].begin(), mp[stoi(s)].end()); string t = to_string(ans); if (count(t.begin(), t.end(), '0') <= cnt) { cout << ans << endl; } else { cout << -1 << endl; } } else { cout << -1 << endl; } } return 0; }