結果
問題 |
No.3204 Permuted Integer
|
ユーザー |
|
提出日時 | 2025-07-18 21:38:58 |
言語 | C# (.NET 8.0.404) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,737 bytes |
コンパイル時間 | 12,109 ms |
コンパイル使用メモリ | 170,104 KB |
実行使用メモリ | 30,136 KB |
最終ジャッジ日時 | 2025-07-18 21:39:25 |
合計ジャッジ時間 | 16,501 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | TLE * 1 -- * 24 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (169 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var t = NN; var ans = new int[t]; for (var u = 0; u < t; ++u) { var s = ReadLine(); var list = new int[s.Length]; ans[u] = int.MaxValue; Permutate(s.Length, perm => { var d = 0; for (var i = 0; i < perm.Length; ++i) d = d * 10 + s[perm[i]] - '0'; var sq = (int)Math.Sqrt(d); if (sq * sq == d) ans[u] = Math.Min(ans[u], d); }); if (ans[u] == int.MaxValue) ans[u] = -1; } WriteLine(string.Join("\n", ans)); } static void Permutate(int n, Action<int[]> action) { var seed = new int[n]; for (var i = 0; i < n; ++i) seed[i] = i; var used = new bool[n]; var perm = new int[n]; Permutate(0, seed, perm, used, action); } static void Permutate(int pos, int[] seed, int[] perm, bool[] used, Action<int[]> action) { if (pos == used.Length) action(perm); for (var i = 0; i < used.Length; ++i) { if (used[i]) continue; perm[pos] = seed[i]; used[i] = true; Permutate(pos + 1, seed, perm, used, action); used[i] = false; } } }