結果

問題 No.1896 Arrays and XOR Procedure 2
ユーザー 👑 kakel-sankakel-san
提出日時 2023-11-19 20:19:58
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 2,626 bytes
コンパイル時間 6,981 ms
コンパイル使用メモリ 158,232 KB
実行使用メモリ 181,256 KB
最終ジャッジ日時 2023-11-19 20:20:13
合計ジャッジ時間 13,909 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
32,804 KB
testcase_01 AC 76 ms
32,804 KB
testcase_02 AC 76 ms
32,804 KB
testcase_03 AC 92 ms
33,572 KB
testcase_04 AC 86 ms
34,212 KB
testcase_05 AC 80 ms
34,212 KB
testcase_06 AC 79 ms
33,828 KB
testcase_07 AC 80 ms
34,212 KB
testcase_08 AC 81 ms
33,828 KB
testcase_09 AC 79 ms
33,828 KB
testcase_10 AC 82 ms
33,828 KB
testcase_11 AC 83 ms
33,828 KB
testcase_12 AC 84 ms
33,828 KB
testcase_13 AC 79 ms
33,700 KB
testcase_14 AC 78 ms
33,700 KB
testcase_15 AC 78 ms
33,700 KB
testcase_16 AC 79 ms
33,700 KB
testcase_17 AC 80 ms
33,700 KB
testcase_18 AC 84 ms
33,444 KB
testcase_19 AC 77 ms
33,188 KB
testcase_20 AC 80 ms
33,700 KB
testcase_21 AC 78 ms
33,188 KB
testcase_22 AC 80 ms
33,828 KB
testcase_23 AC 79 ms
33,828 KB
testcase_24 AC 80 ms
33,828 KB
testcase_25 AC 85 ms
33,828 KB
testcase_26 AC 79 ms
33,828 KB
testcase_27 AC 80 ms
33,828 KB
testcase_28 AC 78 ms
33,572 KB
testcase_29 AC 79 ms
181,256 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();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = NN;
        var a = NList;
        var b = NList;
        var ans = Xor(n, a, b);
        WriteLine(ans.Count);
        if (ans.Count > 0) WriteLine(string.Join("\n", ans));
    }
    static List<string> Xor(int n, int[] a, int[] b)
    {
        var bits = 0;
        for (var i = 0; i < n; ++i)
        {
            bits = Math.Max(bits, Bits(a[i]));
            bits = Math.Max(bits, Bits(b[i]));
        }
        var abit = new int[n];
        var bbit = new int[n];
        for (var i = 0; i < n; ++i)
        {
            abit[i] = (a[i] >> bits - 1) & 1;
            bbit[i] = (b[i] >> bits - 1) & 1;
        }
        var apos = -1;
        var bpos = -1;
        for (var i = 0; i < n; ++i)
        {
            if (abit[i] == 1) apos = i;
            if (bbit[i] == 1) bpos = i;
        }
        var ans = new List<string>();
        if (apos < 0)
        {
            ans.Add($"1 {n} {bpos + 1}");
            apos = n - 1;
            abit[n - 1] = 1;
        }
        if (bpos < 0)
        {
            ans.Add($"2 {apos + 1} {n}");
            bpos = n - 1;
            bbit[n - 1] = 1;
        }
        for (var i = 0; i < n; ++i)
        {
            if (i != apos && abit[i] == 1)
            {
                ans.Add($"1 {i + 1} {bpos + 1}");
            }
            if (i != bpos && bbit[i] == 0)
            {
                ans.Add($"2 {apos + 1} {i + 1}");
            }
        }
        ans.Add($"1 {apos + 1} {bpos + 1}");
        return ans;
    }
    static bool Check(int n, int[] _a, int[] _b, List<string> ans)
    {
        var a = _a.ToArray();
        var b = _b.ToArray();
        foreach (var q in ans)
        {
            var c = q.Split();
            var kind = int.Parse(c[0]);
            var x = int.Parse(c[1]) - 1;
            var y = int.Parse(c[2]) - 1;
            if (kind == 1)
            {
                a[x] ^= b[y];
            }
            else
            {
                b[y] ^= a[x];
            }
        }
        return a.Max() < b.Min();
    }
    static int Bits(int n)
    {
        var ans = 0;
        while (n > 0)
        {
            ++ans;
            n >>= 1;
        }
        return ans;
    }
}
0