結果
問題 |
No.1092 modular arithmetic
|
ユーザー |
|
提出日時 | 2020-06-26 23:50:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 929 bytes |
コンパイル時間 | 1,641 ms |
コンパイル使用メモリ | 170,036 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-05 00:50:12 |
合計ジャッジ時間 | 3,920 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; }