結果
| 問題 |
No.90 品物の並び替え
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-03-29 16:29:53 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 2,625 ms / 5,000 ms |
| コード長 | 3,159 bytes |
| コンパイル時間 | 2,452 ms |
| コンパイル使用メモリ | 106,496 KB |
| 実行使用メモリ | 82,464 KB |
| 最終ジャッジ日時 | 2024-10-02 07:27:23 |
| 合計ジャッジ時間 | 4,984 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
public class Program
{
public void Proc() {
Reader.IsDebug = false;
int[] inpt = Reader.GetInt();
int itemCount = inpt[0];
int seiyakuCount = inpt[1];
for(int i=0; i<seiyakuCount; i++) {
this.SeiyakuList.Add(new Seiyaku(Reader.GetInt()));
}
List<int> targetNum = new List<int>();
for(int i=0; i<itemCount; i++) {
targetNum.Add(i);
}
List<List<int>> list = this.GetList(targetNum);
int ans = 0;
foreach (List<int> subList in list)
{
ans = Math.Max(ans, this.GetScore(subList));
}
Console.WriteLine(ans);
}
private int GetScore(List<int> target) {
int ans = 0;
foreach (Seiyaku se in this.SeiyakuList)
{
int idx1 = target.IndexOf(se.Before);
int idx2 = target.IndexOf(se.After);
if(idx1 < idx2) {
ans += se.Point;
}
}
return ans;
}
private List<List<int>> GetList(List<int> target) {
List<List<int>> ans = new List<List<int>>();
if(target.Count == 1) {
List<int> num = new List<int>();
num.Add(target[0]);
ans.Add(num);
return ans;
}
for(int i=0; i<target.Count; i++) {
List<int> subList = new List<int>();
subList.AddRange(target);
subList.RemoveAt(i);
List<List<int>> ret = this.GetList(subList);
foreach (List<int> retSub in ret)
{
List<int> tmp = new List<int>();
retSub.Add(target[i]);
ans.Add(retSub);
}
}
return ans;
}
private List<Seiyaku> SeiyakuList = new List<Seiyaku>();
public class Seiyaku {
public int Before;
public int After;
public int Point;
public Seiyaku(int[] init) {
this.Before = init[0];
this.After = init[1];
this.Point = init[2];
}
}
public class Reader {
private static String InitText = @"
4 9
0 1 1
0 2 2
0 3 3
1 2 4
1 3 5
2 3 6
3 2 100
2 1 100
1 0 100
";
private static System.IO.StringReader sr = null;
public static bool IsDebug = true;
public static string ReadLine() {
if(IsDebug) {
if(sr == null) {
sr = new System.IO.StringReader(InitText.Trim());
}
return sr.ReadLine();
} else {
return Console.ReadLine();
}
}
public static int[] GetInt(char delimiter = ' ') {
string[] inpt = ReadLine().Split(delimiter);
int[] ret = new int[inpt.Length];
for(int i=0; i<inpt.Length; i++) {
ret[i] = int.Parse(inpt[i]);
}
return ret;
}
}
public static void Main(string[] args)
{
Program prg = new Program();
prg.Proc();
}
}
14番