結果

問題 No.2219 Re:010
ユーザー vjudge1
提出日時 2025-01-22 14:29:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,109 bytes
コンパイル時間 1,838 ms
コンパイル使用メモリ 192,600 KB
実行使用メモリ 11,880 KB
最終ジャッジ日時 2025-01-22 14:29:24
合計ジャッジ時間 3,317 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |         scanf("%s",s+1);
      |         ~~~~~^~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
char s[200010];
int n,mod,ans,tmp,z[200010],two[200010],zz[200010],w[200010],ww[200010];
signed main(){
	mod=998244353*1ll;
	scanf("%s",s+1);
	n=strlen(s+1);
    for(int i=1;i<=n;i++){
    	if(s[i]=='?'){
    		w[i]=w[i-1]+1ll;
    		z[i]=z[i-1];
		}
		else if(s[i]=='0'){
			w[i]=w[i-1];
			z[i]=z[i-1]+1ll;
		}
		else{
			w[i]=w[i-1];
			z[i]=z[i-1];
		}
	}
	for(int i=n;i>=1;i--){
		if(s[i]=='?'){
    		ww[i]=ww[i+1]+1ll;
    		zz[i]=zz[i+1];
		}
		else if(s[i]=='0'){
			ww[i]=ww[i+1];
			zz[i]=zz[i+1]+1ll;
		}
		else{
			ww[i]=ww[i+1];
			zz[i]=zz[i+1];
		}
	}
	two[0]=1ll;
	for(int i=1;i<=n;i++) two[i]=(two[i-1]*2ll)%mod;
	for(int i=1;i<=n;i++){
		if(s[i]!='0'){
			tmp=two[w[i-1]+ww[i+1]]*(z[i-1]*zz[i+1])%mod;
			if(w[i-1]>0) tmp=(tmp+two[w[i-1]+ww[i+1]-1]*w[i-1]*zz[i+1]%mod)%mod;																														
			if(ww[i+1]>0) tmp=(tmp+two[w[i-1]+ww[i+1]-1]*ww[i+1]*z[i-1]%mod)%mod;
			if(w[i-1]>0&&ww[i+1]>0) tmp=(tmp+two[w[i-1]+ww[i+1]-2]*w[i-1]*ww[i+1]%mod)%mod;
			ans=(ans+tmp)%mod;
		}
	}
	printf("%lld",ans);
	return 0;
}
0