結果

問題 No.1092 modular arithmetic
ユーザー kotatsugamekotatsugame
提出日時 2020-06-24 07:31:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 427 bytes
コンパイル時間 486 ms
コンパイル使用メモリ 64,312 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 20:47:19
合計ジャッジ時間 3,443 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 41 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 59 ms
4,376 KB
testcase_04 AC 48 ms
4,376 KB
testcase_05 AC 48 ms
4,376 KB
testcase_06 AC 34 ms
4,376 KB
testcase_07 AC 46 ms
4,380 KB
testcase_08 AC 53 ms
4,376 KB
testcase_09 AC 46 ms
4,376 KB
testcase_10 AC 40 ms
4,376 KB
testcase_11 AC 43 ms
4,380 KB
testcase_12 AC 33 ms
4,380 KB
testcase_13 AC 13 ms
4,380 KB
testcase_14 AC 15 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 12 ms
4,376 KB
testcase_17 AC 15 ms
4,380 KB
testcase_18 AC 56 ms
4,376 KB
testcase_19 AC 35 ms
4,376 KB
testcase_20 AC 61 ms
4,376 KB
testcase_21 AC 44 ms
4,380 KB
testcase_22 AC 55 ms
4,376 KB
testcase_23 AC 90 ms
4,380 KB
testcase_24 AC 29 ms
4,376 KB
testcase_25 AC 72 ms
4,380 KB
testcase_26 AC 90 ms
4,376 KB
testcase_27 AC 15 ms
4,380 KB
testcase_28 AC 73 ms
4,376 KB
testcase_29 AC 109 ms
4,380 KB
testcase_30 AC 71 ms
4,380 KB
testcase_31 AC 10 ms
4,380 KB
testcase_32 AC 64 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:6:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-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