結果
| 問題 |
No.2071 Shift and OR
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-16 22:12:25 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,689 bytes |
| コンパイル時間 | 4,152 ms |
| コンパイル使用メモリ | 107,264 KB |
| 実行使用メモリ | 38,016 KB |
| 最終ジャッジ日時 | 2024-12-21 21:11:44 |
| 合計ジャッジ時間 | 6,320 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 WA * 19 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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;
}
}