結果

問題 No.1340 おーじ君をさがせ
ユーザー keymoonkeymoon
提出日時 2021-01-16 00:54:54
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 563 ms / 2,000 ms
コード長 3,018 bytes
コンパイル時間 952 ms
コンパイル使用メモリ 115,148 KB
実行使用メモリ 23,040 KB
最終ジャッジ日時 2024-05-05 22:01:39
合計ジャッジ時間 11,271 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
19,200 KB
testcase_01 AC 32 ms
18,944 KB
testcase_02 AC 32 ms
18,944 KB
testcase_03 AC 31 ms
18,944 KB
testcase_04 AC 31 ms
19,072 KB
testcase_05 AC 31 ms
19,072 KB
testcase_06 AC 31 ms
19,072 KB
testcase_07 AC 31 ms
18,944 KB
testcase_08 AC 31 ms
19,072 KB
testcase_09 AC 31 ms
18,816 KB
testcase_10 AC 32 ms
19,072 KB
testcase_11 AC 121 ms
19,328 KB
testcase_12 AC 47 ms
18,944 KB
testcase_13 AC 98 ms
19,456 KB
testcase_14 AC 217 ms
19,132 KB
testcase_15 AC 186 ms
19,456 KB
testcase_16 AC 44 ms
19,200 KB
testcase_17 AC 83 ms
19,200 KB
testcase_18 AC 123 ms
19,328 KB
testcase_19 AC 35 ms
19,200 KB
testcase_20 AC 32 ms
19,072 KB
testcase_21 AC 131 ms
22,656 KB
testcase_22 AC 281 ms
21,888 KB
testcase_23 AC 147 ms
22,656 KB
testcase_24 AC 511 ms
19,968 KB
testcase_25 AC 47 ms
22,656 KB
testcase_26 AC 41 ms
21,248 KB
testcase_27 AC 38 ms
20,480 KB
testcase_28 AC 51 ms
22,272 KB
testcase_29 AC 36 ms
20,864 KB
testcase_30 AC 156 ms
22,656 KB
testcase_31 AC 516 ms
23,040 KB
testcase_32 AC 486 ms
22,784 KB
testcase_33 AC 563 ms
22,784 KB
testcase_34 AC 436 ms
22,784 KB
testcase_35 AC 524 ms
22,656 KB
testcase_36 AC 31 ms
19,072 KB
testcase_37 AC 41 ms
22,656 KB
testcase_38 AC 519 ms
22,784 KB
testcase_39 AC 181 ms
22,656 KB
testcase_40 AC 188 ms
22,788 KB
testcase_41 AC 187 ms
22,524 KB
testcase_42 AC 31 ms
19,072 KB
testcase_43 AC 32 ms
19,200 KB
testcase_44 AC 31 ms
19,072 KB
testcase_45 AC 32 ms
19,072 KB
testcase_46 AC 143 ms
19,968 KB
testcase_47 AC 147 ms
19,584 KB
testcase_48 AC 160 ms
19,972 KB
testcase_49 AC 158 ms
19,268 KB
testcase_50 AC 158 ms
19,256 KB
testcase_51 AC 160 ms
19,008 KB
testcase_52 AC 277 ms
19,140 KB
testcase_53 AC 268 ms
19,264 KB
testcase_54 AC 276 ms
19,268 KB
testcase_55 AC 219 ms
19,692 KB
testcase_56 AC 30 ms
19,072 KB
testcase_57 AC 31 ms
18,944 KB
testcase_58 AC 32 ms
19,200 KB
testcase_59 AC 104 ms
19,072 KB
testcase_60 AC 32 ms
19,072 KB
testcase_61 AC 104 ms
18,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

//ignore
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var nmt = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var n = (int)nmt[0];
        var m = (int)nmt[1];
        var t = nmt[2];
        Matrix mat = new Matrix(n, n);
        for (int i = 0; i < m; i++)
        {
            var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = ab[0];
            var b = ab[1];
            mat[b, a] = true;
        }
        Matrix iv = new Matrix(n, 1);
        iv[0, 0] = true;
        var res = Power(mat, t) * iv;
        Console.WriteLine(Enumerable.Range(0, n).Count(x => res[x, 0]));
    }

    static Matrix Power(Matrix n, long m)
    {
        Matrix pow = n;
        Matrix res = Matrix.Delta(n.Height, true);
        while (m > 0)
        {
            if ((m & 1) == 1) res *= pow;
            pow *= pow;
            m >>= 1;
        }
        return res;
    }
}

class Matrix
{
    public readonly int Height;
    public readonly int Width;
    bool[] data;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public Matrix(int height, int width)
    {
        data = new bool[height * width];
        Height = height;
        Width = width;
    }
    public bool this[int i, int j]
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get { return data[i * Width + j]; }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        set { data[i * Width + j] = value; }
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static Matrix Delta(int n, bool val)
    {
        var res = new Matrix(n, n);
        for (int i = 0; i < n; i++) res[i, i] = val;
        return res;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static Matrix Add(Matrix a, Matrix b)
    {
        var res = new Matrix(a.Height, a.Width);
        for (int i = 0; i < a.Height; i++) for (int j = 0; j < a.Width; j++) res[i, j] = a[i, j] | b[i, j];
        return res;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static Matrix Mul(Matrix a, Matrix b)
    {
        var res = new Matrix(a.Height, b.Width);
        for (int i = 0; i < a.Height; i++) for (int j = 0; j < b.Width; j++) for (int k = 0; k < a.Width; k++) res[i, j] |= a[i, k] & b[k, j];
        return res;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static Matrix operator +(Matrix a, Matrix b) => Add(a, b);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static Matrix operator *(Matrix a, Matrix b) => Mul(a, b);
}
0