結果

問題 No.360 増加門松列
ユーザー mbanmban
提出日時 2017-01-10 06:31:04
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 2,957 bytes
コンパイル時間 2,243 ms
コンパイル使用メモリ 106,180 KB
実行使用メモリ 23,600 KB
最終ジャッジ日時 2023-08-25 18:41:27
合計ジャッジ時間 4,552 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
21,396 KB
testcase_01 AC 58 ms
19,340 KB
testcase_02 AC 57 ms
21,476 KB
testcase_03 AC 57 ms
23,448 KB
testcase_04 AC 58 ms
21,420 KB
testcase_05 AC 59 ms
19,376 KB
testcase_06 AC 59 ms
21,440 KB
testcase_07 AC 60 ms
21,444 KB
testcase_08 AC 59 ms
23,584 KB
testcase_09 AC 59 ms
21,412 KB
testcase_10 AC 58 ms
21,400 KB
testcase_11 AC 56 ms
21,396 KB
testcase_12 AC 59 ms
21,460 KB
testcase_13 AC 58 ms
23,600 KB
testcase_14 AC 59 ms
23,520 KB
testcase_15 AC 57 ms
21,328 KB
testcase_16 AC 57 ms
23,472 KB
testcase_17 AC 57 ms
21,380 KB
testcase_18 AC 59 ms
21,388 KB
testcase_19 AC 58 ms
21,476 KB
testcase_20 AC 59 ms
23,472 KB
testcase_21 AC 58 ms
21,448 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;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;


class Magatro
{
    static Scanner sc = new Scanner();

    static void Main()
    {
        int[] array = new int[7];
        for (int i = 0; i < 7; i++)
        {
            array[i] = i;
        }
        int[] D = new int[7];
        for (int i = 0; i < 7; i++)
        {
            D[i] = sc.NextInt();
        }
        while (next_permutation(array))
        {
            int[] A = new int[7];
            
            for (int i = 0; i < 7; i++)
            {
                A[i] = D[array[i]];
            }
           // Console.WriteLine(string.Join(" ", A));
            if (ZoukaKadomatu(A))
            {
                Console.WriteLine("YES");
                return;
            }
        }
        Console.WriteLine("NO");

    }
    static bool ZoukaKadomatu(int[] array)
    {
        for (int i = 0; i < 5; i++)
        {
            if (!Kadomatu(array[i], array[i + 1], array[i + 2]))
            {
                return false;
            }
        }
        return true;
    }
    static bool Kadomatu(params int[] arr)
    {
        if (arr[0] == arr[1] || arr[0] == arr[2] || arr[1] == arr[2])
        {
            return false;
        }
        if (arr.Min() != arr[1] && arr.Max() != arr[1])
        {
            return false;
        }
        if (arr[0] > arr[2])
        {
            return false;
        }
        return true;
    }
    static bool next_permutation(int[] perm)
    {
        int n = perm.Length;
        int k = -1;
        for (int i = 1; i < n; i++)
            if (perm[i - 1] < perm[i])
                k = i - 1;
        if (k == -1)
        {
            for (int i = 0; i < n; i++)
                perm[i] = i;
            return false;
        }
        int l = k + 1;
        for (int i = l; i < n; i++)
            if (perm[k] < perm[i])
                l = i;
        int t = perm[k];
        perm[k] = perm[l];
        perm[l] = t;
        Array.Reverse(perm, k + 1, perm.Length - (k + 1));
        return true;
    }
}

public class Scanner
{
    public string[] S;
    private int Index;
    private char Separator;
    public Scanner(char separator=' ')
    {
        Index = 0;
        Separator = separator;
    }
    public string Next()
    {
        string result;
        if (S == null || Index >= S.Length)
        {
            S = Line();
            Index = 0;
        }
        result = S[Index];
        Index++;
        return result;
    }
    private string[] Line()
    {
        return Console.ReadLine().Split(Separator);
    } 
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
}
0