結果

問題 No.482 あなたの名は
ユーザー threecoursethreecourse
提出日時 2018-05-16 11:16:34
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 2,180 bytes
コンパイル時間 2,612 ms
コンパイル使用メモリ 107,664 KB
実行使用メモリ 41,400 KB
最終ジャッジ日時 2023-09-10 22:17:09
合計ジャッジ時間 7,545 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
21,904 KB
testcase_01 AC 66 ms
23,760 KB
testcase_02 AC 64 ms
22,036 KB
testcase_03 AC 65 ms
23,708 KB
testcase_04 AC 63 ms
21,864 KB
testcase_05 AC 64 ms
21,948 KB
testcase_06 AC 64 ms
19,840 KB
testcase_07 AC 72 ms
22,060 KB
testcase_08 AC 71 ms
22,204 KB
testcase_09 AC 71 ms
21,988 KB
testcase_10 AC 73 ms
24,092 KB
testcase_11 AC 72 ms
20,136 KB
testcase_12 AC 74 ms
24,100 KB
testcase_13 AC 72 ms
22,048 KB
testcase_14 AC 72 ms
22,132 KB
testcase_15 AC 140 ms
41,376 KB
testcase_16 AC 138 ms
37,392 KB
testcase_17 AC 140 ms
39,308 KB
testcase_18 AC 140 ms
41,324 KB
testcase_19 AC 139 ms
39,308 KB
testcase_20 AC 141 ms
37,256 KB
testcase_21 AC 140 ms
39,284 KB
testcase_22 AC 140 ms
39,388 KB
testcase_23 AC 140 ms
39,396 KB
testcase_24 AC 140 ms
39,304 KB
testcase_25 AC 141 ms
39,304 KB
testcase_26 AC 139 ms
41,296 KB
testcase_27 AC 140 ms
41,288 KB
testcase_28 AC 141 ms
39,316 KB
testcase_29 AC 134 ms
41,400 KB
testcase_30 AC 64 ms
21,800 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.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public long N, K;
        public int[] D;
        public bool[] F;

        public void Run()
        {
            {
                var line = Input.ReadLongArray();
                N = line[0];
                K = line[1];
            }
            {
                D = Input.ReadIntArray();
                for (int i = 0; i < N; i++) D[i]--;
            }

            F = new bool[N];

            long C = 0;
            for (int i = 0; i < N; i++)
            {
                int c = 0;
                int d = i;

                if (!F[d])
                {
                    while (true)
                    {
                        F[d] = true;
                        c++;
                        d = D[d];

                        if (F[d])
                        {
                            C += c - 1;
                            break;
                        }
                    }
                }
            }

            bool possible = (C <= K) && ((K - C) % 2 == 0); 
            Console.WriteLine(possible ? "YES" : "NO");
        }
    }

    // libs ----------
    
    // common ----------

    internal static class Input
    {
        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}
0