結果
問題 | No.1612 I hate Construct a Palindrome |
ユーザー | fgwiebfaoish |
提出日時 | 2021-07-21 22:55:13 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,582 bytes |
コンパイル時間 | 1,591 ms |
コンパイル使用メモリ | 116,636 KB |
実行使用メモリ | 67,268 KB |
最終ジャッジ日時 | 2024-07-17 19:59:02 |
合計ジャッジ時間 | 12,022 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
24,748 KB |
testcase_01 | AC | 33 ms
24,888 KB |
testcase_02 | AC | 328 ms
65,144 KB |
testcase_03 | AC | 31 ms
24,624 KB |
testcase_04 | AC | 32 ms
24,632 KB |
testcase_05 | AC | 333 ms
67,268 KB |
testcase_06 | AC | 360 ms
56,876 KB |
testcase_07 | AC | 358 ms
57,392 KB |
testcase_08 | AC | 348 ms
56,484 KB |
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 | AC | 34 ms
24,528 KB |
testcase_23 | WA | - |
testcase_24 | AC | 35 ms
26,540 KB |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 30 ms
24,368 KB |
testcase_28 | AC | 32 ms
24,756 KB |
testcase_29 | AC | 28 ms
24,236 KB |
testcase_30 | AC | 31 ms
24,748 KB |
testcase_31 | AC | 31 ms
24,624 KB |
testcase_32 | AC | 31 ms
24,488 KB |
testcase_33 | AC | 31 ms
22,840 KB |
testcase_34 | AC | 30 ms
22,708 KB |
testcase_35 | AC | 31 ms
24,760 KB |
testcase_36 | AC | 29 ms
26,412 KB |
testcase_37 | AC | 31 ms
24,752 KB |
testcase_38 | AC | 32 ms
24,608 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(); try{ 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(); 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*(Pc(e.Item3)!=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)); } catch{Console.WriteLine(-1);} } 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));} }