Submission #13287183


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.From == 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 2416 Byte
Status WA
Exec Time 342 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 30 ms 11604 KB
a02 AC 29 ms 11476 KB
a03 AC 29 ms 11476 KB
after_contest_57 WA 133 ms 11420 KB
after_contest_58 WA 132 ms 11420 KB
after_contest_59 WA 133 ms 11420 KB
b04 AC 29 ms 11476 KB
b05 AC 29 ms 11476 KB
b06 AC 29 ms 11476 KB
b07 AC 28 ms 11476 KB
b08 AC 29 ms 11476 KB
b09 AC 77 ms 11420 KB
b10 AC 133 ms 13596 KB
b11 AC 99 ms 11420 KB
b12 AC 72 ms 9372 KB
b13 AC 112 ms 11420 KB
b14 AC 123 ms 11420 KB
b15 AC 37 ms 15516 KB
b16 AC 37 ms 11548 KB
b17 AC 35 ms 11420 KB
b18 AC 133 ms 11420 KB
b19 AC 133 ms 11420 KB
b20 AC 77 ms 11420 KB
b21 AC 78 ms 13468 KB
b22 AC 175 ms 11420 KB
b23 AC 133 ms 13468 KB
b24 AC 186 ms 13468 KB
b25 AC 29 ms 11508 KB
b26 AC 215 ms 11488 KB
b27 AC 215 ms 13536 KB
b28 AC 214 ms 13536 KB
b29 AC 129 ms 13536 KB
b30 AC 129 ms 13536 KB
b31 AC 128 ms 13536 KB
b32 AC 215 ms 11360 KB
b33 AC 217 ms 13536 KB
b34 AC 217 ms 13536 KB
b35 AC 218 ms 13536 KB
b36 AC 218 ms 13536 KB
b37 AC 221 ms 15584 KB
b38 AC 217 ms 13536 KB
b39 AC 216 ms 11488 KB
b40 AC 216 ms 13536 KB
b41 AC 219 ms 15584 KB
b42 AC 217 ms 15584 KB
b43 AC 205 ms 11488 KB
b44 AC 207 ms 13536 KB
b45 AC 206 ms 15584 KB
b46 AC 197 ms 15584 KB
b47 AC 342 ms 13536 KB
b48 AC 117 ms 13468 KB
b49 AC 135 ms 11420 KB
b50 AC 103 ms 11420 KB
b51 AC 77 ms 11420 KB
b52 AC 102 ms 9372 KB
b53 AC 98 ms 11420 KB
b54 AC 197 ms 13536 KB
b55 AC 223 ms 11488 KB
b56 AC 235 ms 13536 KB