Submission #13287396


Source Code Expand

Copy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramE
    {
        private class Edge {
            public int From {get;set;}
            public int To {get;set;}
            public long Cost {get;set;}
        }
        static void Main()
        {
            int n = NextInt, m = NextInt, p = NextInt;
            var edges = TakeLine(m).Select(l => new Edge{From = (int)l[0] - 1, To = (int)l[1] - 1, Cost = l[2] - p}).ToArray();
            var distance = Enumerable.Repeat(long.MinValue >> 2, n).ToArray();
            distance[0] = 0;

            for (int i = 0; i <= 2 * n; i++)
            {
                foreach (var edge in edges)
                {
                    if (distance[edge.To] < distance[edge.From] + edge.Cost)
                    {
                        distance[edge.To] = distance[edge.From] + edge.Cost;
                        if (i >= n - 1 && edge.To == n - 1)
                        {
                            System.Console.WriteLine(-1);
                            return;
                        }
                    }
                }
            }

            System.Console.WriteLine(Math.Max(0, distance[n - 1]));
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}

Submission Info

Submission Time
Task E - Coins Respawn
User asurato
Language C# (Mono 4.6.2.0)
Score 500
Code Size 2392 Byte
Status WA
Exec Time 337 ms
Memory 15584 KB

Judge Result

Set Name Sample All after_contest
Score / Max Score 0 / 0 500 / 500 0 / 0
Status
AC × 3
AC × 56
WA × 3
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49, b50, b51, b52, b53, b54, b55, b56
after_contest after_contest_57, after_contest_58, after_contest_59
Case Name Status Exec Time Memory
a01 AC 28 ms 11476 KB
a02 AC 28 ms 13524 KB
a03 AC 28 ms 11476 KB
after_contest_57 WA 131 ms 11420 KB
after_contest_58 WA 132 ms 11548 KB
after_contest_59 WA 131 ms 11548 KB
b04 AC 28 ms 11476 KB
b05 AC 28 ms 11476 KB
b06 AC 28 ms 11476 KB
b07 AC 29 ms 13524 KB
b08 AC 28 ms 11476 KB
b09 AC 75 ms 11420 KB
b10 AC 132 ms 13468 KB
b11 AC 97 ms 9372 KB
b12 AC 112 ms 13468 KB
b13 AC 110 ms 13468 KB
b14 AC 120 ms 11420 KB
b15 AC 36 ms 15516 KB
b16 AC 34 ms 11420 KB
b17 AC 35 ms 15516 KB
b18 AC 131 ms 9500 KB
b19 AC 132 ms 9500 KB
b20 AC 75 ms 11420 KB
b21 AC 77 ms 11420 KB
b22 AC 170 ms 9372 KB
b23 AC 130 ms 11420 KB
b24 AC 175 ms 11420 KB
b25 AC 28 ms 13556 KB
b26 AC 212 ms 13536 KB
b27 AC 212 ms 13536 KB
b28 AC 211 ms 13536 KB
b29 AC 127 ms 13536 KB
b30 AC 127 ms 13536 KB
b31 AC 125 ms 15584 KB
b32 AC 211 ms 11488 KB
b33 AC 215 ms 15584 KB
b34 AC 213 ms 13536 KB
b35 AC 215 ms 13536 KB
b36 AC 214 ms 11488 KB
b37 AC 217 ms 13536 KB
b38 AC 213 ms 13536 KB
b39 AC 214 ms 13536 KB
b40 AC 214 ms 13536 KB
b41 AC 215 ms 15584 KB
b42 AC 215 ms 13536 KB
b43 AC 201 ms 11488 KB
b44 AC 201 ms 13536 KB
b45 AC 203 ms 13536 KB
b46 AC 194 ms 11488 KB
b47 AC 337 ms 13536 KB
b48 AC 115 ms 11420 KB
b49 AC 134 ms 9500 KB
b50 AC 101 ms 9372 KB
b51 AC 75 ms 11420 KB
b52 AC 101 ms 13468 KB
b53 AC 97 ms 11420 KB
b54 AC 194 ms 11488 KB
b55 AC 222 ms 13536 KB
b56 AC 232 ms 13536 KB