結果
問題 |
No.90 品物の並び替え
|
ユーザー |
![]() |
提出日時 | 2017-09-04 16:46:13 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,140 bytes |
コンパイル時間 | 1,139 ms |
コンパイル使用メモリ | 115,108 KB |
実行使用メモリ | 23,808 KB |
最終ジャッジ日時 | 2024-11-06 20:54:26 |
合計ジャッジ時間 | 10,125 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 TLE * 1 |
コンパイルメッセージ
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; namespace SortItems { class Program { static void Main(string[] args) { int[] P = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int R = MainProcess(P[0],P[1]); Console.WriteLine(R); } private static int MainProcess(int N, int M) { int[][] itemlines = new int[M][]; for(int i = 0; i < M; i++) { itemlines[i] = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); } int[] items = new int[N]; for(int i = 0; i < N; i++) { items[i] = i; } int R = 0; var perm = new Permutation(); foreach (var n in perm.Enumerate(items)) { int S = 0, idx0 = 0, idx1 = 0; for (int i = 0; i < M; i++) { for(int j = 0;j < N; j++) { if (itemlines[i][0] == n[j]) idx0 = j; if (itemlines[i][1] == n[j]) idx1 = j; } if(idx0 < idx1) { S += itemlines[i][2]; } } R = Math.Max(R, S); } return R; } } /* * Copy from http://qiita.com/gushwell/items/8780fc2b71f2182f36ac */ public class Permutation { public IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items) { if (items.Count() == 1) { yield return new T[] { items.First() }; yield break; } foreach (var item in items) { var leftside = new T[] { item }; var unused = items.Except(leftside); foreach (var rightside in Enumerate(unused)) { yield return leftside.Concat(rightside).ToArray(); } } } } }