結果

問題 No.90 品物の並び替え
ユーザー kuuso1kuuso1
提出日時 2014-12-07 19:22:30
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,833 ms / 5,000 ms
コード長 1,854 bytes
コンパイル時間 3,277 ms
コンパイル使用メモリ 109,168 KB
実行使用メモリ 29,012 KB
最終ジャッジ日時 2023-09-02 09:19:53
合計ジャッジ時間 5,963 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
20,680 KB
testcase_01 AC 164 ms
24,792 KB
testcase_02 AC 58 ms
20,608 KB
testcase_03 AC 64 ms
20,756 KB
testcase_04 AC 68 ms
22,764 KB
testcase_05 AC 184 ms
24,780 KB
testcase_06 AC 142 ms
29,012 KB
testcase_07 AC 58 ms
20,812 KB
testcase_08 AC 60 ms
20,748 KB
testcase_09 AC 1,833 ms
24,792 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.Collections;
using System.Collections.Generic;
 
class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int[] A=new int[N];
		for(int i=0;i<N;i++)A[i]=i;
		
		
		int max=0;
		do{
			int cnt=0;
			for(int j=0;j<M;j++){
				int idx1=-1;
				int idx2=-1;
				for(int i=0;i<N;i++){
					if(A[i]==info[j][0])idx1=i;
					if(A[i]==info[j][1])idx2=i;
				}
				if(idx2>idx1)cnt+=info[j][2];
			}
//for(int ii=0;ii<N;ii++)Console.Write("{0} ",A[ii]);Console.WriteLine("cnt={0}",cnt);
			max=Math.Max(cnt,max);
		}while(NextPermutaion(A));
		
		Console.WriteLine(max);
		
		
		
		
		
	}
	
	int N,M;
	int[][] info;
	public Sol(){
		var d=ria();
		N=d[0];M=d[1];
		info=new int[M][] ;
		for(int i=0;i<M;i++)info[i]=ria();
	}



	static public bool NextPermutaion<T>(T[] A)where T:IComparable<T>{
		for(int i=A.Length-2;i>=0;i--){
			if(A[i].CompareTo(A[i+1])<0){
				int trgt=Array.FindLastIndex(A,x=>A[i].CompareTo(x)<0);
				Swap(ref A[i],ref A[trgt]);
				Array.Reverse(A,i+1,A.Length-(i+1));
				return true;
			}
		}
		Array.Reverse(A);
		return false;
	}
	static void Swap<T>(ref T x, ref T y){
		T t=x;x=y;y=t;
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}
0