結果
| 問題 |
No.90 品物の並び替え
|
| コンテスト | |
| ユーザー |
kuuso1
|
| 提出日時 | 2014-12-07 19:22:30 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 1,952 ms / 5,000 ms |
| コード長 | 1,854 bytes |
| コンパイル時間 | 2,341 ms |
| コンパイル使用メモリ | 107,904 KB |
| 実行使用メモリ | 22,016 KB |
| 最終ジャッジ日時 | 2024-06-11 16:07:45 |
| 合計ジャッジ時間 | 3,965 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
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));}
}
kuuso1