結果
| 問題 | No.1092 modular arithmetic |
| ユーザー |
|
| 提出日時 | 2026-08-30 10:57:37 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 39 ms / 2,000 ms |
| + 835µs | |
| コード長 | 629 bytes |
| 記録 | |
| コンパイル時間 | 3,601 ms |
| コンパイル使用メモリ | 351,872 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-08-30 10:57:45 |
| 合計ジャッジ時間 | 6,180 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll modpow(ll a, ll e, ll m){
ll r = 1;
while (e){
if (e&1) r = r*a%m;
a = a*a%m;
e >>= 1;
}
return r;
}
int main(){
int P, N;
cin >> P >> N;
vector<int> A(N);
string S;
for (int& x : A) cin >> x;
cin >> S;
ll now = A[0];
for (int i = 1; i < N; i++){
if (S[i-1] == '+') now = (now+A[i])%P;
else if (S[i-1] == '-') now = (now-A[i]+P)%P;
else if (S[i-1] == '*') now = (now*A[i])%P;
else now = (now*modpow(A[i], P-2, P))%P;
}
cout << now << endl;
}