結果
問題 | No.1239 Multiplication -2 |
ユーザー | fgwiebfaoish |
提出日時 | 2020-09-29 17:36:30 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,987 bytes |
コンパイル時間 | 1,587 ms |
コンパイル使用メモリ | 108,800 KB |
実行使用メモリ | 42,368 KB |
最終ジャッジ日時 | 2024-07-04 01:46:04 |
合計ジャッジ時間 | 5,669 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 24 ms
18,048 KB |
testcase_01 | AC | 23 ms
18,048 KB |
testcase_02 | AC | 24 ms
17,664 KB |
testcase_03 | AC | 29 ms
18,560 KB |
testcase_04 | AC | 31 ms
18,560 KB |
testcase_05 | AC | 29 ms
18,688 KB |
testcase_06 | AC | 27 ms
18,560 KB |
testcase_07 | AC | 27 ms
18,688 KB |
testcase_08 | AC | 23 ms
18,048 KB |
testcase_09 | AC | 22 ms
18,048 KB |
testcase_10 | AC | 22 ms
17,920 KB |
testcase_11 | AC | 22 ms
17,920 KB |
testcase_12 | AC | 23 ms
17,920 KB |
testcase_13 | AC | 23 ms
18,048 KB |
testcase_14 | AC | 23 ms
17,920 KB |
testcase_15 | AC | 69 ms
23,680 KB |
testcase_16 | AC | 98 ms
27,648 KB |
testcase_17 | AC | 156 ms
40,448 KB |
testcase_18 | WA | - |
testcase_19 | AC | 160 ms
40,960 KB |
testcase_20 | WA | - |
testcase_21 | AC | 155 ms
40,064 KB |
testcase_22 | AC | 153 ms
38,912 KB |
testcase_23 | AC | 124 ms
36,864 KB |
testcase_24 | AC | 115 ms
31,744 KB |
testcase_25 | AC | 96 ms
28,160 KB |
testcase_26 | AC | 114 ms
30,720 KB |
testcase_27 | AC | 64 ms
22,528 KB |
testcase_28 | AC | 149 ms
38,400 KB |
testcase_29 | AC | 162 ms
40,448 KB |
testcase_30 | RE | - |
testcase_31 | AC | 105 ms
29,184 KB |
testcase_32 | AC | 179 ms
41,472 KB |
testcase_33 | AC | 121 ms
31,232 KB |
testcase_34 | AC | 115 ms
30,080 KB |
testcase_35 | AC | 71 ms
23,808 KB |
testcase_36 | AC | 65 ms
22,912 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; using System.Diagnostics; //using nint=System.Int32; static class Program{ const int mod=998244353; //const double eps=1e-11; static void Main(){ Sc sc=new Sc(); var n=sc.I; var a=sc.Ia2; var g=new int[n+1]; var u=new int[n+1]; var f=new int[n+1]; var r=new long[][]{new long[n+2],new long[n+2]}; var rr=new long[n+1]; rr[n]=rr[n-1]=1; for(int i = n-2;i>0;i--) {rr[i]=(rr[i+1]<<1)%mod;} for(int i = 1,k=0;i<=n;i++) { r[0][i]=r[0][i-1]; r[1][i]=r[1][i-1]; f[i]=f[i-1]; if(a[i]<0){ f[i]++; k^=1; } if(a[i]!=0){ r[k][i]+=rr[i]; r[k][i]%=mod; } } Mint z=1; for(int i = n,j=n+1,k=n+1;i>=0;i--,z*=2) { g[i]=j; u[i]=k; if((a[i]&1)==0){j=i;} if(a[i]==-1){k=i;} } Mint ans=0,v=1; for(int i = 1;i<=n;i++) { if(a[i]==-1){ if((g[i]==n||a[g[i]]==0)||((f[g[i]]-f[i])%2==1&&g[g[i]]<u[g[i]])){ v=Fp(2,i-1); continue; } int p=(f[g[i]]-f[i])%2==1?u[g[i]]:g[i]; ans+=v*(r[f[p]&1][g[p]-1]-r[f[p]&1][p-1]); } else if(Abs(a[i])==2){ int p=a[i]==-2?i:u[i]; if(p==n+1||g[i]<p){ v=Fp(2,i-1); continue; } ans+=v*(r[f[p]&1][g[p]-1]-r[f[p]&1][p-1]); } if(a[i]==1){v+=Fp(2,i-1);} else{v=Fp(2,i-1);} } Console.WriteLine("{2}",ans,Fp(2,n-1),ans/Fp(2,n-1)); } static long Fp(long x,long e){ long r=1; while(e>0){ if((e&1)>0){r*=x;r%=mod;} x=(x*x)%mod; e>>=1; } return r; } } public struct Mint{ const int mod=998244353; 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;} private 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 int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).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 long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).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;} }