結果

問題 No.1092 modular arithmetic
ユーザー kotatsugame
提出日時 2020-06-24 07:31:43
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 427 bytes
コンパイル時間 526 ms
コンパイル使用メモリ 65,376 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-03 19:55:58
合計ジャッジ時間 3,190 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
long mod,N,A[1<<17];
string S;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
main()
{
	cin>>mod>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	cin>>S;
	long X=A[0];
	for(int i=0;i<N;i++)
	{
		if(S[i]=='+')X=(X+A[i+1])%mod;
		else if(S[i]=='-')X=(X+mod-A[i+1])%mod;
		else if(S[i]=='*')X=X*A[i+1]%mod;
		else if(S[i]=='/')X=X*power(A[i+1],mod-2)%mod;
	}
	cout<<X<<endl;
}
0