結果

問題 No.698 ペアでチームを作ろう
ユーザー バカらっくバカらっく
提出日時 2018-06-10 11:02:11
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 67 ms / 1,000 ms
コード長 1,906 bytes
コンパイル時間 4,000 ms
コンパイル使用メモリ 107,916 KB
実行使用メモリ 23,824 KB
最終ジャッジ日時 2023-09-13 02:35:29
合計ジャッジ時間 4,706 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
19,648 KB
testcase_01 AC 64 ms
21,760 KB
testcase_02 AC 64 ms
21,804 KB
testcase_03 AC 66 ms
21,660 KB
testcase_04 AC 65 ms
21,600 KB
testcase_05 AC 66 ms
23,716 KB
testcase_06 AC 66 ms
21,724 KB
testcase_07 AC 66 ms
21,748 KB
testcase_08 AC 67 ms
23,824 KB
testcase_09 AC 67 ms
19,616 KB
testcase_10 AC 65 ms
23,692 KB
testcase_11 AC 65 ms
21,704 KB
testcase_12 AC 67 ms
21,600 KB
testcase_13 AC 66 ms
21,668 KB
testcase_14 AC 65 ms
21,828 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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();
    }
}
0