結果
問題 | No.1239 Multiplication -2 |
ユーザー | fgwiebfaoish |
提出日時 | 2020-09-29 17:45:08 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 192 ms / 2,000 ms |
コード長 | 5,037 bytes |
コンパイル時間 | 1,776 ms |
コンパイル使用メモリ | 115,748 KB |
実行使用メモリ | 49,388 KB |
最終ジャッジ日時 | 2024-07-04 02:00:27 |
合計ジャッジ時間 | 5,797 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 27 ms
23,932 KB |
testcase_01 | AC | 28 ms
24,296 KB |
testcase_02 | AC | 28 ms
23,932 KB |
testcase_03 | AC | 34 ms
24,884 KB |
testcase_04 | AC | 33 ms
22,708 KB |
testcase_05 | AC | 33 ms
26,500 KB |
testcase_06 | AC | 33 ms
24,316 KB |
testcase_07 | AC | 33 ms
24,512 KB |
testcase_08 | AC | 28 ms
25,808 KB |
testcase_09 | AC | 28 ms
22,068 KB |
testcase_10 | AC | 28 ms
23,852 KB |
testcase_11 | AC | 28 ms
24,024 KB |
testcase_12 | AC | 28 ms
24,112 KB |
testcase_13 | AC | 28 ms
26,096 KB |
testcase_14 | AC | 28 ms
24,052 KB |
testcase_15 | AC | 77 ms
28,032 KB |
testcase_16 | AC | 107 ms
31,372 KB |
testcase_17 | AC | 177 ms
46,500 KB |
testcase_18 | AC | 177 ms
48,420 KB |
testcase_19 | AC | 182 ms
46,872 KB |
testcase_20 | AC | 188 ms
48,648 KB |
testcase_21 | AC | 175 ms
46,172 KB |
testcase_22 | AC | 168 ms
47,188 KB |
testcase_23 | AC | 143 ms
42,852 KB |
testcase_24 | AC | 129 ms
37,756 KB |
testcase_25 | AC | 106 ms
33,504 KB |
testcase_26 | AC | 122 ms
34,848 KB |
testcase_27 | AC | 70 ms
29,428 KB |
testcase_28 | AC | 170 ms
46,608 KB |
testcase_29 | AC | 182 ms
48,664 KB |
testcase_30 | AC | 91 ms
31,448 KB |
testcase_31 | AC | 118 ms
34,148 KB |
testcase_32 | AC | 192 ms
49,388 KB |
testcase_33 | AC | 135 ms
38,072 KB |
testcase_34 | AC | 129 ms
34,616 KB |
testcase_35 | AC | 77 ms
27,844 KB |
testcase_36 | AC | 74 ms
27,696 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]; if(p==n+1){ v=Fp(2,i-1); continue; } ans+=v*(mod+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*(mod+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("{0}",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;} }