結果
| 問題 | No.1092 modular arithmetic |
| ユーザー |
|
| 提出日時 | 2020-06-26 23:50:55 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 929 bytes |
| 記録 | |
| コンパイル時間 | 1,165 ms |
| コンパイル使用メモリ | 182,740 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-03-26 07:28:48 |
| 合計ジャッジ時間 | 3,108 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 7 WA * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr char newl = '\n';
constexpr ll MOD = 1000000007;
ll modpow(ll x, ll n, ll mod = MOD) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll p;
int n;
cin >> p >> n;
vector<ll> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
string s;
cin >> s;
ll ans = a.front();
for (int i = 0; i < n - 1; i++) {
if (s[i] == '+') {
(ans += a[i + 1]) %= p;
} else if (s[i] == '-') {
(ans += p - a[i + 1]) %= p;
} else if (s[i] == '*') {
(ans *= a[i + 1]) %= p;
} else {
(ans *= modpow(a[i + 1], p - 2)) %= p;
}
}
cout << ans << newl;
return 0;
}