結果
問題 | No.90 品物の並び替え |
ユーザー |
![]() |
提出日時 | 2018-07-04 19:40:21 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 2,183 ms / 5,000 ms |
コード長 | 1,503 bytes |
コンパイル時間 | 4,102 ms |
コンパイル使用メモリ | 115,448 KB |
実行使用メモリ | 47,780 KB |
最終ジャッジ日時 | 2024-07-01 02:16:13 |
合計ジャッジ時間 | 5,877 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace YukiCoder{class Program{static IEnumerable<string> Permu(string str){if (str.Length == 1) yield return str;char[] pa = str.ToCharArray();for (int i = 0; i < pa.Length; i++){char c = pa[i]; pa[i] = pa[0]; pa[0] = c;foreach (var s in Permu(new string(pa, 1, pa.Length - 1))){yield return c + s;}}}static void Main(string[] args){var va = Console.ReadLine().Split().Select(int.Parse).ToArray();int[][] pia = new int[va[1]][];for (int i = 0; i < va[1]; i++){pia[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();}var vb = Enumerable.Range(0, va[0]).Select(n => (char)(n + '0')).ToArray();int sMax = 0;Permu(new string(vb)).ToList().ForEach(s =>{int sum = 0;for(int i=0; i<pia.Count(); i++){int na = s.IndexOf((char)(pia[i][0] + '0'));int nb = s.IndexOf((char)(pia[i][1] + '0'));if (na < nb) sum += pia[i][2];}if (sum > sMax) sMax = sum;});Console.WriteLine(sMax);}}}