結果

問題 No.1092 modular arithmetic
ユーザー beetbeet
提出日時 2020-08-08 17:12:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 2,237 bytes
コンパイル時間 1,872 ms
コンパイル使用メモリ 197,320 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 21:08:29
合計ジャッジ時間 4,314 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 14 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 24 ms
6,944 KB
testcase_04 AC 21 ms
6,940 KB
testcase_05 AC 20 ms
6,940 KB
testcase_06 AC 16 ms
6,944 KB
testcase_07 AC 20 ms
6,940 KB
testcase_08 AC 23 ms
6,940 KB
testcase_09 AC 19 ms
6,940 KB
testcase_10 AC 17 ms
6,940 KB
testcase_11 AC 19 ms
6,944 KB
testcase_12 AC 16 ms
6,940 KB
testcase_13 AC 6 ms
6,940 KB
testcase_14 AC 7 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 5 ms
6,944 KB
testcase_17 AC 7 ms
6,940 KB
testcase_18 AC 24 ms
6,948 KB
testcase_19 AC 15 ms
6,944 KB
testcase_20 AC 25 ms
6,940 KB
testcase_21 AC 20 ms
6,944 KB
testcase_22 AC 24 ms
6,944 KB
testcase_23 AC 46 ms
6,944 KB
testcase_24 AC 15 ms
6,940 KB
testcase_25 AC 35 ms
6,940 KB
testcase_26 AC 42 ms
6,944 KB
testcase_27 AC 8 ms
6,940 KB
testcase_28 AC 34 ms
6,944 KB
testcase_29 AC 53 ms
6,944 KB
testcase_30 AC 35 ms
6,944 KB
testcase_31 AC 5 ms
6,944 KB
testcase_32 AC 32 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define PROBLEM "https://yukicoder.me/problems/4569"

#include<bits/stdc++.h>
using namespace std;

#define call_from_test

#ifndef call_from_test
#include <bits/stdc++.h>
using namespace std;
#endif

//BEGIN CUT HERE
template<typename T=int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}
//END CUT HERE
#ifndef call_from_test
signed main(){
  return 0;
}
#endif


#ifndef call_from_test
#include <bits/stdc++.h>
using namespace std;
#endif
//BEGIN CUT HERE
template<typename T>
struct Rint{
  static T mod;
  static void set_mod(T nmod){mod=nmod;}

  T v;
  Rint():v(0){}
  Rint(signed v):v(v){}
  Rint(long long t){v=t%mod;if(v<0) v+=mod;}

  Rint pow(long long k){
    Rint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Rint add_identity(){return Rint(0);}
  static Rint mul_identity(){return Rint(1);}

  Rint inv(){return pow(mod-2);}

  Rint& operator+=(Rint a){v+=a.v;if(v>=mod)v-=mod;return *this;}
  Rint& operator-=(Rint a){v+=mod-a.v;if(v>=mod)v-=mod;return *this;}
  Rint& operator*=(Rint a){v=1LL*v*a.v%mod;return *this;}
  Rint& operator/=(Rint a){return (*this)*=a.inv();}

  Rint operator+(Rint a) const{return Rint(v)+=a;}
  Rint operator-(Rint a) const{return Rint(v)-=a;}
  Rint operator*(Rint a) const{return Rint(v)*=a;}
  Rint operator/(Rint a) const{return Rint(v)/=a;}

  Rint operator-() const{return v?Rint(mod-v):Rint(v);}

  bool operator==(const Rint a)const{return v==a.v;}
  bool operator!=(const Rint a)const{return v!=a.v;}
  bool operator <(const Rint a)const{return v <a.v;}
};
template<typename T> T Rint<T>::mod;
template<typename T>
ostream& operator<<(ostream &os,Rint<T> m){os<<m.v;return os;}
//END CUT HERE
#ifndef call_from_test
signed main(){
  return 0;
}
#endif

#undef call_from_test

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int p,n;
  cin>>p>>n;
  auto as=read(n);
  string s;
  cin>>s;

  using R = Rint<int>;
  R::set_mod(p);
  R ans(as[0]);
  for(int i=1;i<n;i++){
    if(s[i-1]=='+') ans+=R(as[i]);
    if(s[i-1]=='-') ans-=R(as[i]);
    if(s[i-1]=='*') ans*=R(as[i]);
    if(s[i-1]=='/') ans/=R(as[i]);
  }

  cout<<ans<<endl;
  return 0;
}
0