結果

問題 No.1239 Multiplication -2
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2020-09-29 17:25:56
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 4,964 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 112,100 KB
実行使用メモリ 50,712 KB
最終ジャッジ日時 2024-07-04 01:34:15
合計ジャッジ時間 5,839 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
23,904 KB
testcase_01 AC 26 ms
24,284 KB
testcase_02 AC 25 ms
26,196 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 26 ms
23,856 KB
testcase_09 AC 26 ms
25,960 KB
testcase_10 AC 26 ms
24,160 KB
testcase_11 WA -
testcase_12 AC 26 ms
26,192 KB
testcase_13 AC 25 ms
24,240 KB
testcase_14 AC 26 ms
24,008 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 172 ms
46,872 KB
testcase_18 WA -
testcase_19 AC 177 ms
44,928 KB
testcase_20 WA -
testcase_21 AC 164 ms
46,168 KB
testcase_22 AC 161 ms
47,184 KB
testcase_23 AC 136 ms
42,576 KB
testcase_24 AC 124 ms
37,872 KB
testcase_25 AC 103 ms
35,472 KB
testcase_26 AC 119 ms
34,580 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 RE -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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((a[i]&2)!=0){
				int p=a[i]==-2?i:u[i];
				if(p==n+1){
					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("{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;}
}
0