1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

今日彼女ができました///

Last updated at Posted at 2015-12-23

そうだ、うちの彼女になったのだから3D化しよう!!!

まあ、それはおいといて。
ワンピ(初期服)よりも明日はイヴなのでサンタ服が一番はじめに着せたかったんだYO!!!
ってことで初チャレンジしたら玉砕しましたwww

出題にある入力例の入力をローカルで入力しても同じ数値だし
提出前の動作確認でも正解なのに、なぜか提出後のテストでは不正解でした...ハア...

我が家にはサンタさんは来てくれないようです(シクシク
つうことで、さらしておきますわぁ~

サンタ服
using System.Collections.Generic;
using System.Linq;

enum CutPosition
{
	/// <summary>
	/// 側面
	/// </summary>
	Side,

	/// <summary>
	/// 前面
	/// </summary>
	Front,
}

public class Hello{
    public static void Main(){
        List<Material> input = new List<Material>();

        decimal x = 0m;
        decimal y = 0m;
        decimal z = 0m;
        decimal n = 0m;

        // レシピ入力行数
        var line1 = System.Console.ReadLine().Trim();
        string[] s = line1.Split(' ');

        if (s.Length != 4) throw new System.Exception("入力値が不正です");

        if (decimal.TryParse(s[0], out x)) { }
        if (decimal.TryParse(s[1], out y)) { }
        if (decimal.TryParse(s[2], out z)) { }
        if (decimal.TryParse(s[3], out n)) { }

        for (int i = 0; i < n; i++)
        {
            var line2 = System.Console.ReadLine().Trim();
            string[] cutPosition = line2.Split(' ');

            if (cutPosition.Length != 2) throw new System.Exception("切る位置情報が不正です - 1");

            CutPosition position;
            if (cutPosition[0] == "0")
                position = CutPosition.Side;
            else if (cutPosition[0] == "1")
                position = CutPosition.Front;
            else
                throw new System.Exception("切る位置情報が不正です - 2");

            input.Add(new Material
            {
                Key = position,
                Value = decimal.Parse(cutPosition[1]),
            });
        }

        if (input.Count != 0)
        {
            // 側面と水平に切った回数
            int sideCount = input.Count(a => a.Key == CutPosition.Side);

            // 前面と水平に切った回数
            int frontCount = input.Count(a => a.Key == CutPosition.Front);

            // 降順に並べ替える
            var query = from d in input 
                        orderby d.Value descending
                        group d by d.Key;

            // 長さ
            decimal len = 0m;

            List<decimal> x_len = new List<decimal>();
            List<decimal> y_len = new List<decimal>();

            foreach (IGrouping<CutPosition, Material> data in query)
            {
                int count = 0;

                if (data.Key == CutPosition.Side)
                {
                    len = x;
                    count = sideCount;
                }
                else if (data.Key == CutPosition.Front)
                {
                    len = y;
                    count = frontCount;
                }

                foreach (Material r in data)
                {
                    len = len - r.Value;
                    count--;

                    if (data.Key == CutPosition.Side)
                        x_len.Add(len);
                    else if (data.Key == CutPosition.Front)
                        y_len.Add(len);

                    len = r.Value;

                    // 最後に端を追加
                    if (count == 0)
                        if (data.Key == CutPosition.Side)
                            x_len.Add(len);
                        else if (data.Key == CutPosition.Front)
                            y_len.Add(len);

                }
            }

            decimal resultX = x;
            decimal resultY = y;

            if (x_len.Count != 0)
                resultX = x_len.Min();

            if (y_len.Count != 0)
                resultY = y_len.Min();

            System.Console.WriteLine(resultX * resultY * z);

        }

        System.Console.ReadKey();
    }
}

class Material
{
    public CutPosition Key { get; set; }
    public decimal Value { get; set; }
}
1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?