結果
問題 | No.698 ペアでチームを作ろう |
ユーザー | AreTrash |
提出日時 | 2018-06-09 20:55:53 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 60 ms / 1,000 ms |
コード長 | 3,891 bytes |
コンパイル時間 | 934 ms |
コンパイル使用メモリ | 110,080 KB |
実行使用メモリ | 19,328 KB |
最終ジャッジ日時 | 2024-06-30 13:01:54 |
合計ジャッジ時間 | 2,256 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
19,072 KB |
testcase_01 | AC | 26 ms
18,816 KB |
testcase_02 | AC | 28 ms
19,200 KB |
testcase_03 | AC | 28 ms
18,816 KB |
testcase_04 | AC | 30 ms
18,944 KB |
testcase_05 | AC | 28 ms
19,328 KB |
testcase_06 | AC | 28 ms
19,200 KB |
testcase_07 | AC | 57 ms
18,944 KB |
testcase_08 | AC | 57 ms
19,072 KB |
testcase_09 | AC | 58 ms
19,072 KB |
testcase_10 | AC | 60 ms
19,072 KB |
testcase_11 | AC | 59 ms
19,200 KB |
testcase_12 | AC | 58 ms
18,944 KB |
testcase_13 | AC | 58 ms
19,200 KB |
testcase_14 | AC | 60 ms
19,072 KB |
コンパイルメッセージ
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.Collections.Generic; using System.Linq; namespace No698 { public class Program { int N; int[] A; int[] B; void Solve(StreamScanner ss, StreamWriter sw) { //--------------------------------- N = ss.Next(int.Parse); A = ss.Next(int.Parse, N / 2); B = ss.Next(int.Parse, N / 2); sw.WriteLine(Dfs(N / 2)); //--------------------------------- } int Dfs(int c) { if (c-- == 0) return Permute(); var ret = 0; ret = Math.Max(ret, Dfs(c)); MathX.Swap(ref A[c], ref B[c]); ret = Math.Max(ret, Dfs(c)); MathX.Swap(ref A[c], ref B[c]); return ret; } int Permute() { var a = A.OrderBy(x => x).ToArray(); var ans = 0; do { var power = 0; for (var i = 0; i < N / 2; i++) power += a[i] ^ B[i]; ans = Math.Max(ans, power); } while (MathX.NextPermutation(a)); return ans; } static void Main() { var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput())); var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false}; new Program().Solve(ss, sw); sw.Flush(); } static readonly Func<string, string> String = s => s; } public static partial class MathX { public static void Swap<T>(ref T left, ref T right) { var tmp = left; left = right; right = tmp; } //From: https://stackoverflow.com/questions/11208446/generating-permutations-of-a-set-most-efficiently public static bool NextPermutation(int[] numList) { var largestIndex = -1; for (var i = numList.Length - 2; i >= 0; i--) { if (numList[i] < numList[i + 1]) { largestIndex = i; break; } } if (largestIndex < 0) return false; var largestIndex2 = -1; for (var i = numList.Length - 1; i >= 0; i--) { if (numList[largestIndex] < numList[i]) { largestIndex2 = i; break; } } Swap(ref numList[largestIndex], ref numList[largestIndex2]); for (int i = largestIndex + 1, j = numList.Length - 1; i < j; i++, j--) { Swap(ref numList[i], ref numList[j]); } return true; } } public class StreamScanner { static readonly char[] Sep = {' '}; readonly Queue<string> buffer = new Queue<string>(); readonly TextReader textReader; public StreamScanner(TextReader textReader) { this.textReader = textReader; } public T Next<T>(Func<string, T> parser) { if (buffer.Count != 0) return parser(buffer.Dequeue()); var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries); foreach (var nextString in nextStrings) buffer.Enqueue(nextString); return Next(parser); } public T[] Next<T>(Func<string, T> parser, int x) { var ret = new T[x]; for (var i = 0; i < x; ++i) ret[i] = Next(parser); return ret; } public T[][] Next<T>(Func<string, T> parser, int x, int y) { var ret = new T[y][]; for (var i = 0; i < y; ++i) ret[i] = Next(parser, x); return ret; } } }