結果

問題 No.1952 xooooooooooor
ユーザー 👑 kakel-sankakel-san
提出日時 2024-02-08 21:58:35
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 2,425 bytes
コンパイル時間 12,660 ms
コンパイル使用メモリ 158,604 KB
実行使用メモリ 179,756 KB
最終ジャッジ日時 2024-02-08 21:58:54
合計ジャッジ時間 17,887 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
32,548 KB
testcase_01 AC 71 ms
32,548 KB
testcase_02 AC 70 ms
32,548 KB
testcase_03 AC 74 ms
32,548 KB
testcase_04 AC 71 ms
32,548 KB
testcase_05 AC 71 ms
32,548 KB
testcase_06 AC 70 ms
32,548 KB
testcase_07 AC 70 ms
32,548 KB
testcase_08 AC 71 ms
32,548 KB
testcase_09 AC 76 ms
32,548 KB
testcase_10 AC 71 ms
32,548 KB
testcase_11 AC 70 ms
32,548 KB
testcase_12 AC 70 ms
32,548 KB
testcase_13 AC 70 ms
32,548 KB
testcase_14 AC 74 ms
32,548 KB
testcase_15 AC 72 ms
32,548 KB
testcase_16 AC 70 ms
32,548 KB
testcase_17 AC 71 ms
32,548 KB
testcase_18 AC 90 ms
32,548 KB
testcase_19 AC 71 ms
32,548 KB
testcase_20 AC 71 ms
32,548 KB
testcase_21 AC 71 ms
32,548 KB
testcase_22 AC 75 ms
32,548 KB
testcase_23 AC 71 ms
32,548 KB
testcase_24 AC 70 ms
32,548 KB
testcase_25 AC 70 ms
32,548 KB
testcase_26 AC 71 ms
32,548 KB
testcase_27 AC 75 ms
32,548 KB
testcase_28 AC 75 ms
32,548 KB
testcase_29 AC 75 ms
32,548 KB
testcase_30 AC 75 ms
32,548 KB
testcase_31 AC 75 ms
32,548 KB
testcase_32 AC 71 ms
32,548 KB
testcase_33 AC 71 ms
32,548 KB
testcase_34 AC 72 ms
32,548 KB
testcase_35 AC 71 ms
32,548 KB
testcase_36 AC 75 ms
32,548 KB
testcase_37 AC 71 ms
32,548 KB
testcase_38 AC 71 ms
179,756 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (96 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.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 c = NList;
        var (n, m) = (c[0], c[1]);
        WriteLine(Xor(n, m));
    }
    static long Xor(int n, int m)
    {
        if (n == 0)
        {
            return 0;
        }
        var b = Bits(n);
        var mod = 998_244_353;
        var ans = 0L;
        if (m < 64)
        {
            var dp = new int[b.Count + m - 1];
            for (var i = 0; i < m; ++i) for (var j = 0; j < b.Count; ++j) dp[i + j] ^= b[j];
            var mul = 1L;
            for (var i = 0; i < dp.Length; ++i)
            {
                ans = (ans + dp[i] * mul % mod) % mod;
                mul = mul * 2 % mod;
            }
        }
        else
        {
            var tmp = 0L;
            var sub = 0L;
            var mul = 1L;
            for (var i = 0; i + 1 < b.Count; ++i)
            {
                tmp ^= b[i];
                sub = (sub + tmp * mul % mod) % mod;
                mul = mul * 2 % mod;
            }
            ans = sub;
            tmp ^= b[^1];
            var mul2 = Exp(2, m, mod);
            if (tmp == 1) ans = (ans + mul2 - mul + mod) % mod;
            tmp = 0;
            sub = 0;
            for (var i = b.Count - 1; i > 0; --i)
            {
                tmp ^= b[i];
                sub = (sub * 2 + tmp) % mod;
            }
            ans = (ans + sub * mul2 % mod) % mod;
        }
        return ans;
    }
    static List<int> Bits(int n)
    {
        var ans = new List<int>();
        while (n > 0)
        {
            ans.Add(n % 2);
            n >>= 1;
        }
        return ans;
    }
    static long Exp(long n, long p, int mod)
    {
        long _n = n % mod;
        var _p = p;
        var result = 1L;
        if ((_p & 1) == 1) result *= _n;
        while (_p > 0)
        {
            _n = _n * _n % mod;
            _p >>= 1;
            if ((_p & 1) == 1) result = result * _n % mod;
        }
        return result;
    }
}
0