結果
問題 |
No.3204 Permuted Integer
|
ユーザー |
![]() |
提出日時 | 2025-07-19 17:56:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 1,100 bytes |
コンパイル時間 | 878 ms |
コンパイル使用メモリ | 78,724 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-07-19 17:56:58 |
合計ジャッジ時間 | 2,917 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:52:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 52 | scanf("%d", &tn); | ~~~~~^~~~~~~~~~~ main.cpp:56:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 56 | scanf("%d", &n); | ~~~~~^~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 3204.cc: No.3204 Permuted Integer - yukicoder */ #include<cstdio> #include<cmath> #include<unordered_map> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 1000000000; const int MAX_M = 10; /* typedef */ using ll = long long; using umli = unordered_map<ll,int>; /* global variables */ /* subroutines */ ll cs2bits(int cs[]) { ll bits = 0; for (int i = 9; i >= 0; i--) bits = (bits << 4) | cs[i]; return bits; } /* main */ int main() { umli cache; int cs[10]; for (int y = 1; y * y <= MAX_N; y++) { int x = y * y, m = 0; fill(cs, cs + 10, 0); while (x > 0) cs[x % 10]++, x /= 10, m++; ll bits = cs2bits(cs); while (m <= MAX_M) { if (! cache.count(bits)) cache[bits] = y * y; bits++, m++; } } int tn; scanf("%d", &tn); while (tn--) { int n; scanf("%d", &n); fill(cs, cs + 10, 0); while (n > 0) cs[n % 10]++, n /= 10; ll bits = cs2bits(cs); int minx = cache.count(bits) ? cache[bits] : -1; printf("%d\n", minx); } return 0; }