結果

問題 No.2358 xy+yz+zx=N
ユーザー bluemeganebluemegane
提出日時 2023-06-24 22:52:48
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 2,310 bytes
コンパイル時間 833 ms
コンパイル使用メモリ 63,848 KB
実行使用メモリ 26,792 KB
最終ジャッジ日時 2023-09-14 18:48:58
合計ジャッジ時間 3,375 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
22,692 KB
testcase_01 AC 62 ms
22,724 KB
testcase_02 AC 63 ms
18,668 KB
testcase_03 AC 63 ms
22,640 KB
testcase_04 AC 62 ms
22,716 KB
testcase_05 AC 62 ms
20,716 KB
testcase_06 AC 62 ms
20,796 KB
testcase_07 AC 63 ms
20,808 KB
testcase_08 AC 111 ms
26,792 KB
testcase_09 AC 112 ms
26,732 KB
testcase_10 AC 97 ms
20,876 KB
testcase_11 AC 101 ms
21,248 KB
testcase_12 AC 88 ms
20,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System.Text;
using System.Collections.Generic;
using System;

public class P
{
    public int x { get; set; }
    public int y { get; set; }
    public int z { get; set; }
}

public class Hello
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        getAns(n);
    }
    static void print(List<P> ps)
    {
        var c = 0;
        var sb = new StringBuilder();
        foreach (var x in ps)
        {
            if (x.x == x.y && x.y == x.z)
            {
                c++;
                sb.Append(string.Format("{0} {1} {2}\n", x.x, x.y, x.z));
            }
            else if (x.x == x.y)
            {
                c += 3;
                sb.Append(string.Format("{0} {1} {2}\n", x.x, x.y, x.z));
                sb.Append(string.Format("{0} {1} {2}\n", x.x, x.z, x.y));
                sb.Append(string.Format("{0} {1} {2}\n", x.z, x.x, x.y));
            }
            else if (x.y == x.z)
            {
                c += 3;
                sb.Append(string.Format("{0} {1} {2}\n", x.x, x.y, x.z));
                sb.Append(string.Format("{0} {1} {2}\n", x.y, x.x, x.z));
                sb.Append(string.Format("{0} {1} {2}\n", x.y, x.z, x.x));
            }
            else
            {
                c += 6;
                sb.Append(string.Format("{0} {1} {2}\n", x.x, x.y, x.z));
                sb.Append(string.Format("{0} {1} {2}\n", x.x, x.z, x.y));
                sb.Append(string.Format("{0} {1} {2}\n", x.y, x.x, x.z));
                sb.Append(string.Format("{0} {1} {2}\n", x.y, x.z, x.x));
                sb.Append(string.Format("{0} {1} {2}\n", x.z, x.x, x.y));
                sb.Append(string.Format("{0} {1} {2}\n", x.z, x.y, x.x));
            }
        }
        Console.WriteLine(c);
        Console.Write(sb);
    }
    static void getAns(int n)
    {
        var ps = new List<P>();
        for (int i = 0; i * i <= n; i++)
        {
            for (int j = i; j * j <= n; j++)
            {
                if (i == 0 && j == 0) continue;
                var w = n - i * j;
                if (w % (i + j) == 0)
                {
                    var z = w / (i + j);
                    if (z >= j) ps.Add(new P { x = i, y = j, z = z });
                }
            }
        }
        print(ps);
    }
}
0