結果
問題 | No.1612 I hate Construct a Palindrome |
ユーザー | fgwiebfaoish |
提出日時 | 2021-07-22 00:07:05 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 566 ms / 2,000 ms |
コード長 | 4,558 bytes |
コンパイル時間 | 4,032 ms |
コンパイル使用メモリ | 117,360 KB |
実行使用メモリ | 66,976 KB |
最終ジャッジ日時 | 2024-07-17 20:52:21 |
合計ジャッジ時間 | 12,751 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
24,340 KB |
testcase_01 | AC | 33 ms
24,480 KB |
testcase_02 | AC | 331 ms
66,976 KB |
testcase_03 | AC | 32 ms
26,392 KB |
testcase_04 | AC | 34 ms
26,636 KB |
testcase_05 | AC | 331 ms
64,832 KB |
testcase_06 | AC | 374 ms
53,036 KB |
testcase_07 | AC | 370 ms
55,340 KB |
testcase_08 | AC | 349 ms
54,440 KB |
testcase_09 | AC | 342 ms
55,844 KB |
testcase_10 | AC | 338 ms
55,732 KB |
testcase_11 | AC | 346 ms
53,800 KB |
testcase_12 | AC | 360 ms
56,988 KB |
testcase_13 | AC | 358 ms
54,568 KB |
testcase_14 | AC | 362 ms
56,864 KB |
testcase_15 | AC | 566 ms
62,112 KB |
testcase_16 | AC | 556 ms
62,108 KB |
testcase_17 | AC | 552 ms
62,120 KB |
testcase_18 | AC | 32 ms
26,556 KB |
testcase_19 | AC | 33 ms
24,624 KB |
testcase_20 | AC | 33 ms
24,644 KB |
testcase_21 | AC | 33 ms
24,624 KB |
testcase_22 | AC | 33 ms
22,708 KB |
testcase_23 | AC | 34 ms
24,604 KB |
testcase_24 | AC | 35 ms
24,736 KB |
testcase_25 | AC | 35 ms
26,436 KB |
testcase_26 | AC | 34 ms
24,468 KB |
testcase_27 | AC | 31 ms
24,604 KB |
testcase_28 | AC | 31 ms
24,484 KB |
testcase_29 | AC | 29 ms
26,412 KB |
testcase_30 | AC | 32 ms
24,864 KB |
testcase_31 | AC | 31 ms
24,752 KB |
testcase_32 | AC | 31 ms
24,740 KB |
testcase_33 | AC | 32 ms
24,740 KB |
testcase_34 | AC | 32 ms
24,496 KB |
testcase_35 | AC | 31 ms
26,784 KB |
testcase_36 | AC | 29 ms
26,224 KB |
testcase_37 | AC | 32 ms
26,520 KB |
testcase_38 | AC | 31 ms
24,612 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; static void Main(){ Sc sc=new Sc(); var s=sc.Ia; int n=s[0],m=s[1]; var li=new List<ValueTuple<int,int,int>>[n+1]; var a=new int[n+1][]; var g=new int[n+1][]; for(int i=1;i<=n;i++){ li[i]=new List<ValueTuple<int,int,int>>(); a[i]=new int[]{0,0,0}; g[i]=new int[]{0,0,0}; } var h=new int[26]; var ca=new char[m+1]; for(int i=0;i<m;i++){ var (e1,e2,e3)=sc.Tp3<int,char>(); ca[i+1]=e3; li[e1].Add(ValueTuple.Create(e2,e3-'a',i+1)); li[e2].Add(ValueTuple.Create(e1,e3-'a',i+1)); h[e3-'a']++; } for(int i = 0;i<h.Length;i++) { if(h[i]==m){ Console.WriteLine(-1); return; } } var qu=new Queue<ValueTuple<int,int,long>>(); qu.Enqueue(ValueTuple.Create(1,0,0)); while(qu.Count>0){ var e=qu.Dequeue(); var v=Min(2,Pc(e.Item3)); for(int j = 0;j<li[e.Item1].Count;j++) { var p=e.Item3|(1L<<li[e.Item1][j].Item2); var d=Min(2,Pc(p)); if(g[li[e.Item1][j].Item1][d]==0){ qu.Enqueue((li[e.Item1][j].Item1,e.Item2+1,p)); g[li[e.Item1][j].Item1][d]=e.Item1*(v!=d?-1:1); a[li[e.Item1][j].Item1][d]=li[e.Item1][j].Item3; } } } int z=n,f=2; if(g[z][f]==0){ Console.WriteLine(-1); return; } var lia=new List<int>(); while(f!=0){ lia.Add(a[z][f]); if(g[z][f]<0){ z=Abs(g[z][f]); f--; } else{z=Abs(g[z][f]);} } lia.Reverse(); var c=new int[lia.Count]; for(int i = 0;i<c.Length;i++) {c[i]=ca[lia[i]];} var bo=false; for(int i = 0;i<c.Length;i++) { if(c[i]!=c[c.Length-i-1]){ bo=true; break; } } if(!bo){ lia.Add(lia[lia.Count-1]); lia.Add(lia[lia.Count-1]); } Console.WriteLine("{0}",lia.Count); Console.WriteLine("{0}",string.Join("\n",lia)); } static int Pc(long bits){ bits=(bits&0x55555555)+(bits>>1&0x55555555); bits=(bits&0x33333333)+(bits>>2&0x33333333); bits=(bits&0x0f0f0f0f)+(bits>>4&0x0f0f0f0f); bits=(bits&0x00ff00ff)+(bits>>8&0x00ff00ff); return (int)((bits&0x0000ffff)+(bits>>16&0x0000ffff)); } } 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 (T,T) Tp2<T>(){var s=Console.ReadLine().Split();return (Ct<T>(s[0]),Ct<T>(s[1]));} public (T1,T2) Tp2<T1,T2>(){var s=Console.ReadLine().Split();return (Ct<T1>(s[0]),Ct<T2>(s[1]));} public (T,T,T) Tp3<T>(){var s=Console.ReadLine().Split();return (Ct<T>(s[0]),Ct<T>(s[1]),Ct<T>(s[2]));} public (T1,T1,T2) Tp3<T1,T2>(){var s=Console.ReadLine().Split();return (Ct<T1>(s[0]),Ct<T1>(s[1]),Ct<T2>(s[2]));} private T Ct<T>(string s){return (T)Convert.ChangeType(s,typeof(T));} }