結果

問題 No.1364 [Renaming] Road to Cherry from Zelkova
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2021-01-31 02:12:29
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 4,640 bytes
コンパイル時間 2,782 ms
コンパイル使用メモリ 108,516 KB
実行使用メモリ 50,752 KB
最終ジャッジ日時 2023-09-10 22:57:47
合計ジャッジ時間 22,693 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
20,892 KB
testcase_01 AC 58 ms
22,824 KB
testcase_02 AC 59 ms
20,788 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 154 ms
30,416 KB
testcase_24 AC 163 ms
28,616 KB
testcase_25 AC 304 ms
35,432 KB
testcase_26 AC 453 ms
36,552 KB
testcase_27 AC 366 ms
33,408 KB
testcase_28 AC 234 ms
33,372 KB
testcase_29 AC 354 ms
31,744 KB
testcase_30 AC 242 ms
31,396 KB
testcase_31 AC 184 ms
32,964 KB
testcase_32 AC 288 ms
30,452 KB
testcase_33 AC 438 ms
35,652 KB
testcase_34 AC 414 ms
36,448 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 299 ms
30,004 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 251 ms
41,464 KB
testcase_44 AC 222 ms
38,308 KB
testcase_45 AC 240 ms
50,752 KB
testcase_46 AC 78 ms
31,620 KB
testcase_47 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
using System.Threading;
using System.Runtime.CompilerServices;
static class Program{
	const int mod=(int)1e9+7;
	const long inf=long.MaxValue-1;
	static List<ValueTuple<int,int,int>>[] li;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		int n=s[0]+1,m=s[1];
		li=new List<ValueTuple<int,int,int>>[n+1];
		for(int i=1;i<=n;i++){li[i]=new List<ValueTuple<int,int,int>>();}
		for(int i=0;i<m;i++){
			var e=sc.Ia;
			li[e[0]+1].Add(ValueTuple.Create(e[1]+1,e[2],e[3]));
		}
		var Tp=new Tp(li);
		if(!Tp.bo){
			Console.WriteLine("INF");
			return;
		}
		var dp1=new Mint[n+1];
		var dp2=new Mint[n+1];
		dp2[1]=1;
		for(int i = 0;i < n;i++) {
			for(int j = 0;j < li[Tp.a2[i]].Count;j++) {
				dp1[li[Tp.a2[i]][j].Item1]+=dp2[Tp.a2[i]]*li[Tp.a2[i]][j].Item3*li[Tp.a2[i]][j].Item2+dp1[Tp.a2[i]];
				dp2[li[Tp.a2[i]][j].Item1]+=dp2[Tp.a2[i]]*li[Tp.a2[i]][j].Item3;
			}
		}
		Console.WriteLine(dp1[n]);
	}
}
public struct Mint{
	const int mod=(int)1e9+7;
	private long d;
	public Mint(long d){this.d=d;}
	public static implicit operator Mint(long d){return new Mint(d%mod);}
	public static explicit operator long(Mint d){return d.d;}
	public override string ToString(){return d.ToString();}
	public static Mint operator+(Mint a,long b){a.d=(a.d+b)%mod;return a;}
	public static Mint operator+(Mint a,Mint b){a.d=(a.d+b.d)%mod;return a;}
	public static Mint operator-(Mint a,long b){a.d=(mod+a.d-b)%mod;return a;}
	public static Mint operator-(Mint a,Mint b){a.d=(mod+a.d-b.d)%mod;return a;}
	public static Mint operator*(Mint a,long b){a.d=(a.d*b)%mod;return a;}
	public static Mint operator*(Mint a,Mint b){a.d=(a.d*b.d)%mod;return a;}
	public static Mint operator/(Mint a,long b){a.d=(a.d*Mi(b))%mod;return a;}
	public static Mint operator/(Mint a,Mint b){a.d=(a.d*Mi(b.d))%mod;return a;}
	public static bool operator==(Mint a,long b){return (long)a==b;}
	public static bool operator!=(Mint a,long b){return (long)a!=b;}
	public override bool Equals(object obj){return false;}
	public override int GetHashCode(){return 0;}
	public static long Mi(long a){
		a=(a+mod)%mod;
		long b=mod,u=1,v=0;
		while(b>0){
			long t=a/b;
			a-=t*b;(a,b)=(b,a);
			u-=t*v;(u,v)=(v,u);
		}
		u%=mod;
		if(u<0){u+=mod;}
		return u%mod;
	}
}
public class Tp{
	public int[] a1,a2;
	public bool bo=true;
	public Tp(List<(int,int,int)>[] li){
		int n=li.Length;
		var b=new int[n];
		a1=new int[n];
		a2=new int[n-1];
		var k=n-1;
		for(int i=n-1;i>0;i--) {if(b[i]==0){Fu(i);}}
		void Fu(int a) {
			b[a]=2;
			for(int i=0;i<li[a].Count;i++){
				if(b[li[a][i].Item1]==0){Fu(li[a][i].Item1);}
				else if(b[li[a][i].Item1]==2){bo=false;}
			}
			a1[a]=k;
			a2[--k]=a;
			b[a]=1;
		}
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}
0