結果
| 問題 |
No.698 ペアでチームを作ろう
|
| ユーザー |
バカらっく
|
| 提出日時 | 2018-06-10 11:02:11 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 33 ms / 1,000 ms |
| コード長 | 1,906 bytes |
| コンパイル時間 | 940 ms |
| コンパイル使用メモリ | 115,516 KB |
| 実行使用メモリ | 27,644 KB |
| 最終ジャッジ日時 | 2024-06-30 13:13:29 |
| 合計ジャッジ時間 | 2,080 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
public class Program
{
public void Proc()
{
int itemCount = int.Parse(Reader.ReadLine());
this.Items = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
int ans = GetAns(0, 0);
Console.WriteLine(ans);
}
private Dictionary<int, int> dic = new Dictionary<int, int>();
private int GetAns(int idx, int flags) {
if(idx >= Items.Length) {
return 0;
}
int key = 1 << idx;
if(dic.ContainsKey(flags)) {
return dic[flags];
}
if((key&flags)!=0) {
int ret = GetAns(idx + 1, flags);
dic[flags] = ret;
return ret;
}
int ans = 0;
for (int i = idx + 1; i < Items.Length; i++) {
int subKey = 1 << i;
if((flags&subKey)!=0) {
continue;
}
int val = Items[idx] ^ Items[i];
ans = Math.Max(ans, GetAns(idx + 1, flags + key + (1 << i)) + val);
}
dic[flags] = ans;
return ans;
}
private int[] Items;
public class Reader
{
static StringReader sr;
public static bool IsDebug = false;
public static string ReadLine()
{
if (IsDebug)
{
if (sr == null)
{
sr = new StringReader(InputText.Trim());
}
return sr.ReadLine();
}
else
{
return Console.ReadLine();
}
}
private static string InputText = @"
4
1 2 3 4
";
}
public static void Main(string[] args)
{
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
バカらっく