結果

問題 No.2071 Shift and OR
ユーザー 👑 kakel-sankakel-san
提出日時 2022-09-16 22:12:25
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,689 bytes
コンパイル時間 2,321 ms
コンパイル使用メモリ 70,456 KB
実行使用メモリ 42,180 KB
最終ジャッジ日時 2023-08-23 15:48:43
合計ジャッジ時間 6,057 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
21,572 KB
testcase_01 AC 61 ms
21,420 KB
testcase_02 AC 61 ms
19,496 KB
testcase_03 AC 62 ms
23,676 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 61 ms
23,584 KB
testcase_07 AC 61 ms
21,748 KB
testcase_08 AC 60 ms
21,456 KB
testcase_09 AC 62 ms
23,448 KB
testcase_10 AC 60 ms
21,544 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 59 ms
21,620 KB
testcase_15 WA -
testcase_16 AC 61 ms
23,592 KB
testcase_17 WA -
testcase_18 AC 60 ms
23,536 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 59 ms
21,560 KB
testcase_31 AC 59 ms
21,620 KB
testcase_32 AC 59 ms
21,588 KB
testcase_33 AC 59 ms
21,544 KB
testcase_34 AC 59 ms
21,492 KB
testcase_35 AC 58 ms
23,500 KB
testcase_36 AC 58 ms
21,596 KB
testcase_37 AC 61 ms
23,512 KB
testcase_38 AC 60 ms
21,540 KB
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

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 string[] SList(int n) => Enumerable.Repeat(0, n).Select(_ => ReadLine()).ToArray();
    static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = NN;
        var a = NList;

        var ordlist = new List<int>();
        var ordcnt = 0;
        var ones = 0;
        foreach (var ai in a)
        {
            var cnt = Bits(ai);
            if (cnt > 1)
            {
                ordlist.Add(ai);
                ordcnt += cnt;
            }
            else
            {
                ++ones;
            }
        }
        if (ordcnt + ones >= 16)
        {
            WriteLine(32768);
            return;
        }
        var res = 0;
        Permutate(ordlist.Count, list =>
        {
            var sub = 0;
            for (var i = 0; i < list.Length; ++i)
            {
                var tmp = sub;
                var li = ordlist[list[i]];
                for (var j = 0; j < 16; ++j)
                {
                    sub = Math.Max(sub, tmp | li);
                    li = Shift(li);
                }
            }
            res = Math.Max(res, sub);
        });
        for (var i = 0; i < ones; ++i)
        {
            var tmp = res;
            var li = 1;
            for (var j = 0; j < 16; ++j)
            {
                res = Math.Max(res, tmp | li);
                li = Shift(li);
            }
        }
        WriteLine(res);
    }
    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 int Shift(int a)
    {
        return a / 2 + (1 << 15) * (a % 2);
    }
    static int Bits(int a)
    {
        var res = 0;
        while (a > 0)
        {
            if (a % 2 == 1) ++res;
            a >>= 1;
        }
        return res;
    }
}
0