結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | fgwiebfaoish |
提出日時 | 2021-01-31 04:42:28 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 524 ms / 2,500 ms |
コード長 | 7,027 bytes |
コンパイル時間 | 2,353 ms |
コンパイル使用メモリ | 111,488 KB |
実行使用メモリ | 48,000 KB |
最終ジャッジ日時 | 2024-06-28 15:37:39 |
合計ジャッジ時間 | 16,968 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 28 ms
17,920 KB |
testcase_01 | AC | 29 ms
17,664 KB |
testcase_02 | AC | 29 ms
17,920 KB |
testcase_03 | AC | 28 ms
18,048 KB |
testcase_04 | AC | 28 ms
17,920 KB |
testcase_05 | AC | 27 ms
18,048 KB |
testcase_06 | AC | 28 ms
18,048 KB |
testcase_07 | AC | 28 ms
17,920 KB |
testcase_08 | AC | 51 ms
23,424 KB |
testcase_09 | AC | 39 ms
20,992 KB |
testcase_10 | AC | 54 ms
22,784 KB |
testcase_11 | AC | 48 ms
23,040 KB |
testcase_12 | AC | 55 ms
22,784 KB |
testcase_13 | AC | 316 ms
34,552 KB |
testcase_14 | AC | 452 ms
32,632 KB |
testcase_15 | AC | 430 ms
33,916 KB |
testcase_16 | AC | 324 ms
29,696 KB |
testcase_17 | AC | 170 ms
32,636 KB |
testcase_18 | AC | 507 ms
39,168 KB |
testcase_19 | AC | 524 ms
39,284 KB |
testcase_20 | AC | 512 ms
39,292 KB |
testcase_21 | AC | 510 ms
39,296 KB |
testcase_22 | AC | 524 ms
39,156 KB |
testcase_23 | AC | 130 ms
27,648 KB |
testcase_24 | AC | 143 ms
23,764 KB |
testcase_25 | AC | 301 ms
29,952 KB |
testcase_26 | AC | 461 ms
33,152 KB |
testcase_27 | AC | 365 ms
29,840 KB |
testcase_28 | AC | 217 ms
27,904 KB |
testcase_29 | AC | 346 ms
30,176 KB |
testcase_30 | AC | 232 ms
27,648 KB |
testcase_31 | AC | 164 ms
27,732 KB |
testcase_32 | AC | 278 ms
28,328 KB |
testcase_33 | AC | 444 ms
32,256 KB |
testcase_34 | AC | 425 ms
33,532 KB |
testcase_35 | AC | 429 ms
35,572 KB |
testcase_36 | AC | 475 ms
35,228 KB |
testcase_37 | AC | 284 ms
28,544 KB |
testcase_38 | AC | 403 ms
28,800 KB |
testcase_39 | AC | 400 ms
28,672 KB |
testcase_40 | AC | 397 ms
28,928 KB |
testcase_41 | AC | 399 ms
29,056 KB |
testcase_42 | AC | 395 ms
28,800 KB |
testcase_43 | AC | 232 ms
38,652 KB |
testcase_44 | AC | 204 ms
33,532 KB |
testcase_45 | AC | 231 ms
48,000 KB |
testcase_46 | AC | 52 ms
30,720 KB |
testcase_47 | AC | 28 ms
18,176 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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.ba[n]){ var qu=new Queue<ValueTuple<int,int>>(); qu.Enqueue(ValueTuple.Create(1,0)); var b=new bool[n+1]; while(qu.Count>0){ var e=qu.Dequeue(); if(b[e.Item1]){continue;} b[e.Item1]=true; for(int j = 0;j<li[e.Item1].Count;j++) { if(!b[li[e.Item1][j].Item1]){qu.Enqueue(ValueTuple.Create(li[e.Item1][j].Item1,e.Item2+1));} } } Console.WriteLine(b[n]?"INF":"0"); 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]]*li[Tp.a2[i]][j].Item3; dp2[li[Tp.a2[i]][j].Item1]+=dp2[Tp.a2[i]]*li[Tp.a2[i]][j].Item3; } } Console.WriteLine(dp1[n]); } } public class Tp{ public int[] a1,a2; public bool[] ba; public bool bo=false; 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]; ba=new bool[n]; var k=n-1; var thread=new Thread(new ThreadStart(()=>{ 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){ba[a]=ba[li[a][i].Item1]=bo=true;} } a1[a]=k; a2[--k]=a; b[a]=1; } }),1<<27); thread.Start(); thread.Join(); for(int i=0;i<a2.Length;i++) { for(int j = 0;j<li[a2[i]].Count;j++) {ba[li[a2[i]][j].Item1]|=ba[a2[i]];} } } } 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 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;} } public class Sct{ private StreamReader sr; public Sct(string t){sr=new StreamReader(t);} public int I{get{return int.Parse(sr.ReadLine());}} public long L{get{return long.Parse(sr.ReadLine());}} public double D{get{return double.Parse(sr.ReadLine());}} public string S{get{return sr.ReadLine();}} public int[] Ia{get{return Array.ConvertAll(sr.ReadLine().Split(),int.Parse);}} public long[] La{get{return Array.ConvertAll(sr.ReadLine().Split(),long.Parse);}} public double[] Da{get{return Array.ConvertAll(sr.ReadLine().Split(),double.Parse);}} public string[] Sa{get{return sr.ReadLine().Split();}} public object[] Oa{get{return sr.ReadLine().Split();}} public int[] Ia2{get{return Array.ConvertAll(("0 "+sr.ReadLine()+" 0").Split(),int.Parse);}} public int[] Ia3(string a,string b){return Array.ConvertAll((a+sr.ReadLine()+b).Split(),int.Parse);} public int[] Ia3(int a){return Array.ConvertAll((sr.ReadLine()+" "+a.ToString()).Split(),int.Parse);} public long[] La2{get{return Array.ConvertAll(("0 "+sr.ReadLine()+" 0").Split(),long.Parse);}} public long[] La3(string a,string b){return Array.ConvertAll((a+sr.ReadLine()+b).Split(),long.Parse);} public long[] La3(int a){return Array.ConvertAll((sr.ReadLine()+" "+a.ToString()).Split(),long.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(sr.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,sr.ReadLine().Split());}return a;} }