結果
問題 |
No.1360 [Zelkova 4th Tune] 協和音
|
ユーザー |
![]() |
提出日時 | 2021-01-23 07:53:48 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 298 ms / 2,000 ms |
コード長 | 1,461 bytes |
コンパイル時間 | 5,035 ms |
コンパイル使用メモリ | 106,240 KB |
実行使用メモリ | 23,040 KB |
最終ジャッジ日時 | 2024-12-29 23:15:41 |
合計ジャッジ時間 | 14,324 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 47 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System.Linq; using System.Collections.Generic; using System; public class Hello { public static int n; public static int[] a; public static int[,] b; static void Main() { n = int.Parse(Console.ReadLine().Trim()); string[] line = Console.ReadLine().Trim().Split(' '); a = Array.ConvertAll(line, int.Parse); b = new int[n, n]; for (int i = 0; i < n; i++) { line = Console.ReadLine().Trim().Split(' '); for (int j = 0; j < n; j++) b[i, j] = int.Parse(line[j]); } getAns(); } static long calc(List<int> p) { var res = 0L; var pc = p.Count(); for (int i = 0; i < pc - 1; i++) for (int j = i + 1; j < pc; j++) res += b[p[i] - 1, p[j] - 1]; return res; } static void getAns() { var ans = long.MinValue; var ansp = new List<int>(); var imax = 1 << n; for (int i = 1; i < imax; i++) { var temp = 0L; var p = new List<int>(); for (int j = 0; j < 18; j++) { if (((i >> j) & 1) == 1) { temp += a[j]; p.Add(j + 1); } } temp += calc(p); if (temp > ans) { ans = temp; ansp = p; } } Console.WriteLine(ans); Console.WriteLine(string.Join(" ", ansp)); } }