結果

問題 No.1092 modular arithmetic
ユーザー ikkunjyanaikaikkunjyanaika
提出日時 2020-10-15 19:52:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 2,226 bytes
コンパイル時間 1,765 ms
コンパイル使用メモリ 200,940 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 01:17:33
合計ジャッジ時間 4,117 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 15 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 30 ms
4,380 KB
testcase_04 AC 25 ms
4,380 KB
testcase_05 AC 26 ms
4,376 KB
testcase_06 AC 19 ms
4,376 KB
testcase_07 AC 23 ms
4,380 KB
testcase_08 AC 27 ms
4,376 KB
testcase_09 AC 24 ms
4,376 KB
testcase_10 AC 21 ms
4,380 KB
testcase_11 AC 24 ms
4,376 KB
testcase_12 AC 20 ms
4,376 KB
testcase_13 AC 8 ms
4,376 KB
testcase_14 AC 9 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 31 ms
4,376 KB
testcase_19 AC 20 ms
4,380 KB
testcase_20 AC 32 ms
4,380 KB
testcase_21 AC 26 ms
4,376 KB
testcase_22 AC 30 ms
4,376 KB
testcase_23 AC 62 ms
4,376 KB
testcase_24 AC 20 ms
4,380 KB
testcase_25 AC 47 ms
4,380 KB
testcase_26 AC 56 ms
4,376 KB
testcase_27 AC 9 ms
4,376 KB
testcase_28 AC 49 ms
4,380 KB
testcase_29 AC 78 ms
4,380 KB
testcase_30 AC 52 ms
4,376 KB
testcase_31 AC 7 ms
4,380 KB
testcase_32 AC 45 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

ll mod;
const ll inf=1e18;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define lb(x,a) lower_bound(all(x),a)
#define ub(x,a) upper_bound(all(x),a)
#define maxe(x,a) max_element(all(x))
#define mine(x,a) min_element(all(x))
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 


void solve(){
 ll p,n;
  cin >> p >> n;
  mod=p;
  vll a(n);
  rep(i,0,n) cin >> a[i];
  str s;
  cin >> s;
  mint ans=a[0];
  rep(i,1,n){
   if(s[i-1]=='+') ans+=a[i];
   else if(s[i-1]=='-') ans-=a[i];
   else if(s[i-1]=='*') ans*=a[i]; 
   else ans/=a[i]; 
  }
  
  cout << ans << endl;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}
0