結果

問題 No.862 XORでX
コンテスト
ユーザー kakel-san
提出日時 2026-04-09 22:43:47
言語 C#
(.NET 10.0.201)
コンパイル:
dotnet_c
実行:
/usr/bin/dotnet_wrap
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 2,169 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 11,244 ms
コンパイル使用メモリ 172,292 KB
実行使用メモリ 206,968 KB
最終ジャッジ日時 2026-04-09 22:44:12
合計ジャッジ時間 19,362 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (106 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net10.0/main.dll
  main -> /home/judge/data/code/bin/Release/net10.0/publish/

ソースコード

diff #
raw source code

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 c = NList;
        var (n, x) = (c[0], c[1]);
        WriteLine(string.Join("\n", Divide(n, x)));
    }
    static List<int> Divide(int n, int x)
    {
        if (n > 50000)
        {
            var s1 = DivideInt(100005 - n, x ^ 1);
            var ans = new List<int>();
            for (var i = 1; i <= 100005; ++i) if (!s1.Contains(i)) ans.Add(i);
            return ans;
        }
        else
        {
            return DivideInt(n, x).ToList();
        }
    }
    static HashSet<int> DivideInt(int n, int x)
    {
        var ans = new HashSet<int>();
        var rest = x;
        for (var i = 1; i < n; ++i)
        {
            ans.Add(i);
            rest ^= i;
        }
        if (rest >= n && rest < 100006)
        {
            ans.Add(rest);
            return ans;
        }
        for (var i = 1; i < n; ++i)
        {
            if (i == rest) continue;
            ans.Remove(i);
            {
                var ni = i ^ 32768;
                var nr = rest ^ 32768;
                if (ni > 0 && ni < 100006 && nr > 0 && nr < 100006 && !ans.Contains(ni) && !ans.Contains(nr))
                {
                    ans.Add(ni);
                    ans.Add(nr);
                    return ans;
                }
            }
            {
                var ni = i ^ 65536;
                var nr = rest ^ 65536;
                if (ni > 0 && ni < 100006 && nr > 0 && nr < 100006 && !ans.Contains(ni) && !ans.Contains(nr))
                {
                    ans.Add(ni);
                    ans.Add(nr);
                    return ans;
                }
            }
            ans.Add(i);
        }
        return ans;
    }
}
0