結果

問題 No.5001 排他的論理和でランニング
ユーザー iwkjosec
提出日時 2018-04-05 19:04:45
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,470 ms / 1,500 ms
コード長 1,878 bytes
コンパイル時間 820 ms
実行使用メモリ 47,700 KB
スコア 52,428,749
最終ジャッジ日時 2020-03-12 21:01:15
ジャッジサーバーID
(参考情報)
judge9 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.5.0-beta1-19606-04 (d2bd58c6)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var dt = DateTime.Now;
        var NM = ReadLine().Split().Select(int.Parse).ToArray();
        var N = NM[0];
        var M = NM[1];
        var A = ReadLine().Split().Select(int.Parse).ToArray();

        if (N == M)
        {
            WriteLine(string.Join(" ", A));
            return;
        }

        var r = new XorShift();
        var res = 0;
        for (int i = 0; i < M; i++)
        {
            res ^= A[i];
        }
        byte c = 0;
        while (res != 0xFFFFF)
        {
            var a = r.Next(M);
            var b = r.Next(N - M) + M;
            var mmt = res ^ A[a] ^ A[b];
            if (mmt > res)
            {
                res = mmt;
                var t = A[a];
                A[a] = A[b];
                A[b] = t;
            }
            if (c == 0 && (DateTime.Now - dt).TotalMilliseconds > 1450) break;
            c++;
        }
        WriteLine(string.Join(" ", A.Take(M)));
    }
}

public class XorShift
{
    uint x = 123456789;
    uint y = 362436069;
    uint z = 521288629;
    uint w = 88675123;

    public XorShift()
    {
        var t = (uint)Environment.TickCount;
        x ^= t;
        y ^= Rotate(t, 17);
        z ^= Rotate(t, 31);
        w ^= Rotate(t, 18);
    }

    uint Rotate(uint u, int n) => (u << n) + (u >> 32 - n);

    public int Next()// [0, int.MaxValue)                  
    {
        var t = x ^ x << 11;
        x = y; y = z; z = w;
        t = w = w ^ w >> 19 ^ t ^ t >> 8;
        if (t > int.MaxValue) t = ~t;
        return (int)(t == int.MaxValue ? --t : t);
    }

    public int Next(int maxValue) => (int)(NextDouble() * maxValue);// [0, maxValue)

    public double NextDouble() => (double)Next() / int.MaxValue;// [0.0, 1.0)
}
0