結果

問題 No.2577 Simple Permutation Guess
ユーザー kakel-sankakel-san
提出日時 2023-12-10 00:01:20
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 315 ms / 2,000 ms
コード長 2,636 bytes
コンパイル時間 7,126 ms
コンパイル使用メモリ 166,584 KB
実行使用メモリ 54,096 KB
平均クエリ数 251.88
最終ジャッジ日時 2024-09-27 03:52:15
合計ジャッジ時間 30,147 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
46,808 KB
testcase_01 AC 237 ms
52,040 KB
testcase_02 AC 110 ms
48,344 KB
testcase_03 AC 74 ms
47,192 KB
testcase_04 AC 131 ms
48,728 KB
testcase_05 AC 141 ms
49,112 KB
testcase_06 AC 304 ms
53,848 KB
testcase_07 AC 301 ms
54,096 KB
testcase_08 AC 303 ms
53,592 KB
testcase_09 AC 315 ms
53,848 KB
testcase_10 AC 303 ms
53,968 KB
testcase_11 AC 76 ms
48,040 KB
testcase_12 AC 80 ms
47,832 KB
testcase_13 AC 77 ms
47,448 KB
testcase_14 AC 80 ms
47,320 KB
testcase_15 AC 78 ms
47,448 KB
testcase_16 AC 76 ms
47,576 KB
testcase_17 AC 77 ms
47,184 KB
testcase_18 AC 76 ms
47,832 KB
testcase_19 AC 77 ms
46,808 KB
testcase_20 AC 79 ms
47,440 KB
testcase_21 AC 79 ms
47,672 KB
testcase_22 AC 79 ms
47,704 KB
testcase_23 AC 79 ms
46,936 KB
testcase_24 AC 78 ms
47,320 KB
testcase_25 AC 78 ms
47,444 KB
testcase_26 AC 78 ms
47,832 KB
testcase_27 AC 76 ms
47,692 KB
testcase_28 AC 77 ms
47,544 KB
testcase_29 AC 76 ms
47,684 KB
testcase_30 AC 78 ms
47,576 KB
testcase_31 AC 78 ms
47,192 KB
testcase_32 AC 76 ms
47,436 KB
testcase_33 AC 78 ms
47,704 KB
testcase_34 AC 76 ms
47,192 KB
testcase_35 AC 76 ms
47,704 KB
testcase_36 AC 78 ms
47,444 KB
testcase_37 AC 77 ms
47,576 KB
testcase_38 AC 79 ms
47,576 KB
testcase_39 AC 80 ms
47,192 KB
testcase_40 AC 79 ms
47,576 KB
testcase_41 AC 79 ms
46,808 KB
testcase_42 AC 75 ms
47,184 KB
testcase_43 AC 76 ms
47,052 KB
testcase_44 AC 75 ms
47,320 KB
testcase_45 AC 78 ms
47,448 KB
testcase_46 AC 77 ms
47,576 KB
testcase_47 AC 76 ms
47,320 KB
testcase_48 AC 76 ms
47,576 KB
testcase_49 AC 76 ms
47,320 KB
testcase_50 AC 74 ms
47,320 KB
testcase_51 AC 76 ms
47,832 KB
testcase_52 AC 76 ms
46,920 KB
testcase_53 AC 77 ms
47,032 KB
testcase_54 AC 79 ms
47,320 KB
testcase_55 AC 79 ms
47,492 KB
testcase_56 AC 78 ms
47,320 KB
testcase_57 AC 80 ms
47,704 KB
testcase_58 AC 78 ms
47,320 KB
testcase_59 AC 77 ms
47,320 KB
testcase_60 AC 77 ms
47,576 KB
testcase_61 AC 76 ms
47,440 KB
testcase_62 AC 79 ms
47,704 KB
testcase_63 AC 79 ms
47,576 KB
testcase_64 AC 78 ms
47,320 KB
testcase_65 AC 80 ms
47,320 KB
testcase_66 AC 79 ms
47,488 KB
testcase_67 AC 77 ms
47,576 KB
testcase_68 AC 75 ms
47,192 KB
testcase_69 AC 76 ms
46,936 KB
testcase_70 AC 79 ms
47,556 KB
testcase_71 AC 76 ms
47,448 KB
testcase_72 AC 76 ms
47,320 KB
testcase_73 AC 78 ms
47,320 KB
testcase_74 AC 78 ms
47,184 KB
testcase_75 AC 79 ms
47,448 KB
testcase_76 AC 78 ms
47,576 KB
testcase_77 AC 76 ms
47,192 KB
testcase_78 AC 77 ms
47,440 KB
testcase_79 AC 79 ms
47,064 KB
testcase_80 AC 80 ms
47,600 KB
testcase_81 AC 80 ms
47,448 KB
testcase_82 AC 79 ms
47,232 KB
testcase_83 AC 78 ms
47,288 KB
testcase_84 AC 82 ms
47,448 KB
testcase_85 AC 79 ms
47,548 KB
testcase_86 AC 78 ms
47,448 KB
testcase_87 AC 78 ms
47,456 KB
testcase_88 AC 80 ms
47,328 KB
testcase_89 AC 83 ms
47,456 KB
testcase_90 AC 83 ms
47,456 KB
testcase_91 AC 77 ms
47,456 KB
testcase_92 AC 264 ms
52,320 KB
testcase_93 AC 225 ms
51,808 KB
testcase_94 AC 219 ms
50,912 KB
testcase_95 AC 311 ms
53,720 KB
testcase_96 AC 308 ms
53,212 KB
testcase_97 AC 285 ms
52,960 KB
testcase_98 AC 291 ms
52,960 KB
testcase_99 AC 302 ms
53,388 KB
testcase_100 AC 226 ms
51,168 KB
testcase_101 AC 287 ms
53,456 KB
evil_1_rnd_1.txt AC 575 ms
61,408 KB
evil_1_rnd_2.txt AC 581 ms
61,920 KB
evil_2_big_1.txt AC 678 ms
65,888 KB
evil_2_big_2.txt AC 693 ms
65,760 KB
evil_2_big_3.txt AC 683 ms
66,136 KB
evil_3_sorted_1.txt AC 390 ms
56,024 KB
evil_4_sorted_rev_1.txt AC 330 ms
54,488 KB
evil_4_sorted_rev_2.txt AC 475 ms
58,584 KB
evil_400_sorted.txt AC 652 ms
63,960 KB
evil_400_sorted_rev.txt AC 709 ms
66,648 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (90 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

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 n = NN;
        var ans = n < 10 ? ShortGuess(n) : LongGuess(n);
        WriteLine("! " + string.Join(" ", ans));
    }
    static List<int> ShortGuess(int n)
    {
        var all = new List<List<int>>();
        Permutate(n, list => all.Add(list.Select(ai => ai + 1).ToList()));
        var ok = 0;
        var ng = all.Count;
        while (ng - ok > 1)
        {
            var mid = (ok + ng) / 2;
            var ans = Query(all[mid]);
            if (ans < 0) return new List<int>();
            if (ans > 0) ok = mid;
            else ng = mid;
        }
        return all[ok];
    }
    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;
        }
    }
    static List<int> LongGuess(int n)
    {
        var list = new List<int>(n);
        for (var i = 0; i < n; ++i) list.Add(i + 1);
        var ans = new List<int>(n);
        for (var i = 0; i + 1 < n; ++i)
        {
             var ok = 0;
             var ng = list.Count;
             while (ng - ok > 1)
             {
                var mid = (ok + ng) / 2;
                var a = Query(ans.Concat(list.Skip(mid).Take(1)).Concat(list.Take(mid)).Concat(list.Skip(mid + 1)));
                if (a < 0) return new List<int>();
                if (a > 0) ok = mid;
                else ng = mid;
             }
             ans.Add(list[ok]);
             list.RemoveAt(ok);
        }
        ans.Add(list[0]);
        return ans;
    }
    static int Query(IEnumerable<int> list)
    {
        WriteLine($"? {string.Join(" ", list)}");
        return NN;
    }
}
0