結果
問題 | No.1092 modular arithmetic |
ユーザー | hirayuu_yc |
提出日時 | 2024-03-12 18:50:22 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 14,118 bytes |
コンパイル時間 | 2,968 ms |
コンパイル使用メモリ | 249,948 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-09-29 22:24:28 |
合計ジャッジ時間 | 6,903 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 16 ms
6,820 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | AC | 12 ms
6,816 KB |
testcase_14 | AC | 14 ms
6,816 KB |
testcase_15 | AC | 5 ms
6,816 KB |
testcase_16 | AC | 11 ms
6,816 KB |
testcase_17 | AC | 14 ms
6,816 KB |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
ソースコード
#line 1 "Verify/verify-yuki/yuki_1092-barrett.test.cpp" #define PROBLEM "https://yukicoder.me/problems/no/1092" #line 2 "Template.hpp" //https://tatyam.hatenablog.com/entry/2019/12/15/003634 #include<bits/stdc++.h> using namespace std; using ll=long long; template<class T> using pq=priority_queue<T,vector<T>,greater<T>>; using pll=pair<ll,ll>; const ll LINF=1LL<<60; #define _overload3(_1,_2,_3,name,...) name #define _overload4(_1,_2,_3,_4,name,...) name #define _rep1(i,n) for(ll i=0; i<(n); i++) #define _rep2(i,a,b) for(ll i=(a); i<(b); i++) #define _rep3(i,a,b,c) for(ll i=(a); i<(b); i+=(c)) #define rep(...) _overload4(__VA_ARGS__,_rep3,_rep2,_rep1)(__VA_ARGS__) #define _rrep1(i,n) for(ll i=(n); i-->0;) #define _rrep2(i,a,b) for(ll i=(b); i-->(a);) #define rrep(...) _overload3(__VA_ARGS__,_rrep2,_rrep1)(__VA_ARGS__) #define each(i,...) for(auto&& i:__VA_ARGS__) #define all(i) begin(i),end(i) #define rall(i) rbegin(i),rend(i) template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return true;}else return false;} template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return true;}else return false;} template<class T> ll sum(const T &a){return accumulate(all(a),0LL);} template<class T> auto min(const T &a){return *min_element(all(a));} template<class T> auto max(const T &a){return *max_element(all(a));} inline int scan(){ return getchar(); } inline void scan(int &a){ scanf("%d", &a); } inline void scan(unsigned &a){ scanf("%u", &a); } inline void scan(long &a){ scanf("%ld", &a); } inline void scan(long long &a){ scanf("%lld", &a); } inline void scan(unsigned long long &a){ scanf("%llu", &a); } inline void scan(char &a){ cin >> a; } inline void scan(float &a){ scanf("%f", &a); } inline void scan(double &a){ scanf("%lf", &a); } inline void scan(long double &a){ scanf("%Lf", &a); } inline void scan(vector<bool> &vec){ for(unsigned i = 0; i < vec.size(); i++) { int a; scan(a); vec[i] = a; } } inline void scan(char a[]){ scanf("%s", a); } inline void scan(string &a){ cin >> a; } template<class T> inline void scan(vector<T> &vec); template<class T, size_t size> inline void scan(array<T, size> &vec); template<class T, class L> inline void scan(pair<T, L> &p); template<class T, size_t size> inline void scan(T (&vec)[size]); template<class T> inline void scan(vector<T> &vec){ for(auto &i : vec) scan(i); } template<class T> inline void scan(deque<T> &vec){ for(auto &i : vec) scan(i); } template<class T, size_t size> inline void scan(array<T, size> &vec){ for(auto &i : vec) scan(i); } template<class T, class L> inline void scan(pair<T, L> &p){ scan(p.first); scan(p.second); } template<class T, size_t size> inline void scan(T (&vec)[size]){ for(auto &i : vec) scan(i); } template<class T> inline void scan(T &a){ cin >> a; } inline void in(){} template <class Head, class... Tail> inline void in(Head &head, Tail&... tail){ scan(head); in(tail...); } inline void print(){ putchar(' '); } inline void print(const bool &a){ printf("%d", a); } inline void print(const int &a){ printf("%d", a); } inline void print(const unsigned &a){ printf("%u", a); } inline void print(const long &a){ printf("%ld", a); } inline void print(const long long &a){ printf("%lld", a); } inline void print(const unsigned long long &a){ printf("%llu", a); } inline void print(const char &a){ printf("%c", a); } inline void print(const char a[]){ printf("%s", a); } inline void print(const float &a){ printf("%.15f", a); } inline void print(const double &a){ printf("%.15f", a); } inline void print(const long double &a){ printf("%.15Lf", a); } inline void print(const string &a){ for(auto&& i : a) print(i); } template<class T> inline void print(const vector<T> &vec); template<class T, size_t size> inline void print(const array<T, size> &vec); template<class T, class L> inline void print(const pair<T, L> &p); template<class T, size_t size> inline void print(const T (&vec)[size]); template<class T> inline void print(const vector<T> &vec){ if(vec.empty()) return; print(vec[0]); for(auto i = vec.begin(); ++i != vec.end(); ){ putchar(' '); print(*i); } } template<class T> inline void print(const deque<T> &vec){ if(vec.empty()) return; print(vec[0]); for(auto i = vec.begin(); ++i != vec.end(); ){ putchar(' '); print(*i); } } template<class T, size_t size> inline void print(const array<T, size> &vec){ print(vec[0]); for(auto i = vec.begin(); ++i != vec.end(); ){ putchar(' '); print(*i); } } template<class T, class L> inline void print(const pair<T, L> &p){ print(p.first); putchar(' '); print(p.second); } template<class T, size_t size> inline void print(const T (&vec)[size]){ print(vec[0]); for(auto i = vec; ++i != end(vec); ){ putchar(' '); print(*i); } } template<class T> inline void print(const T &a){ cout << a; } inline int out(){ putchar('\n'); return 0; } template<class T> inline int out(const T &t){ print(t); putchar('\n'); return 0; } template<class Head, class... Tail> inline int out(const Head &head, const Tail&... tail){ print(head); putchar(' '); out(tail...); return 0; } using ld=long double; using ull=unsigned long long; using uint=unsigned int; using pii=pair<int,int>; using pdd=pair<ld,ld>; using tuplis=array<ll,3>; #define vec(type,name,...) vector<type> name(__VA_ARGS__); #define vv(type,name,h,...)vector<vector<type>> name(h,vector<type>(__VA_ARGS__)); #define INT(...) int __VA_ARGS__; in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__; in(__VA_ARGS__) #define ULL(...) ull __VA_ARGS__; in(__VA_ARGS__) #define STR(...) string __VA_ARGS__; in(__VA_ARGS__) #define CHR(...) char __VA_ARGS__; in(__VA_ARGS__) #define LD(...) ld __VA_ARGS__; in(__VA_ARGS__) #define VEC(type,name,size) vector<type> name(size); in(name) #define VV(type, name, h, w) vector<vector<type>> name(h, vector<type>(w)); in(name) template<class T> ld dsum(const T &a){return accumulate(all(a),0.0L);} const int INF=INT_MAX>>1; const ll MINF=1LL<<40; const ld DINF=numeric_limits<ld>::infinity(); const int MODD=1000000007; const int MOD=998244353; const ld EPS=1e-9; const ld PI=3.1415926535897932; const ll four[]={0,1,0,-1,0}; const ll eight[]={0,1,1,0,-1,-1,1,-1,0}; ll intpow(ll a,ll b){ll ret=1;while(b){if(b&1)ret*=a;a*=a;b>>=1;}return ret;} int Yes(bool i=true){return out(i?"Yes":"No");} int No(bool i=true){return out(i?"No":"Yes");} #define len(x) ((int)(x).size()) #define fi first #define se second #line 2 "Math/BarrettModint.hpp" template<uint32_t N> struct BarrettModint{ static constexpr uint32_t _phi(){ uint32_t prime_fact=N; uint32_t ret=N; for(int i=2; i*i<prime_fact; i++){ if(prime_fact%i==0){ ret-=ret/i; while(prime_fact%i==0){ prime_fact/=i; } } } if(prime_fact!=1){ ret-=ret/prime_fact; } return ret; } static constexpr uint64_t Nr=(-1ULL)/N+1; static constexpr uint32_t inv_power=_phi()-1; static_assert(1<N); static_assert(N<(1<<30)); int64_t x; constexpr uint32_t mod(){ return N; } constexpr int64_t _get_mod(uint64_t x){ uint64_t ret=((unsigned __int128)x*Nr)>>64; if(x-ret*N<0){ return x-(ret-1)*N; } return x-ret*N; } constexpr BarrettModint()noexcept{ x=0; } constexpr BarrettModint(int64_t val)noexcept{ x=((val%N)+N)%N; } constexpr uint64_t val()noexcept{ return x; } friend ostream &operator<<(ostream &os,BarrettModint &b){ return os<<b.val(); } constexpr BarrettModint operator+()noexcept{return *this;} constexpr BarrettModint operator-()noexcept{return BarrettModint()-(*this);} constexpr friend BarrettModint operator+(BarrettModint lhs,BarrettModint rhs)noexcept{ return BarrettModint(lhs)+=rhs; } constexpr friend BarrettModint operator-(BarrettModint lhs,BarrettModint rhs)noexcept{ return BarrettModint(lhs)-=rhs; } constexpr friend BarrettModint operator*(BarrettModint lhs,BarrettModint rhs)noexcept{ return BarrettModint(lhs)*=rhs; } constexpr friend BarrettModint operator/(BarrettModint lhs,BarrettModint rhs){ return BarrettModint(lhs)/=rhs; } constexpr BarrettModint operator+=(BarrettModint rhs)noexcept{ x+=rhs.x; if(x>=N)x-=N; return *this; } constexpr BarrettModint operator-=(BarrettModint rhs)noexcept{ x-=rhs.x; if(x<0)x+=N; return *this; } constexpr BarrettModint operator*=(BarrettModint rhs)noexcept{ x=_get_mod(x*rhs.x); return *this; } constexpr BarrettModint operator/=(BarrettModint rhs){ (*this)*=rhs.inv(); return *this; } constexpr BarrettModint& operator++(){ (*this)+=1; return *this; } constexpr BarrettModint& operator--(){ (*this)-=1; return *this; } constexpr BarrettModint operator++(int){ (*this)+=1; return *this; } constexpr BarrettModint operator--(int){ (*this)-=1; return *this; } constexpr bool operator==(BarrettModint rhs)noexcept{ return (x>=N?x-N:x)==(rhs.x>=N?rhs.x-N:rhs.x); } constexpr bool operator!=(BarrettModint rhs)noexcept{ return (x>=N?x-N:x)!=(rhs.x>=N?rhs.x-N:rhs.x); } constexpr BarrettModint inv(){ BarrettModint ret=(*this).pow(inv_power); assert(ret*(*this)==1); return ret; } constexpr BarrettModint pow(uint64_t x)noexcept{ BarrettModint ret=1; BarrettModint bin=(*this); while(x){ if(x&1)ret*=bin; bin*=bin; x>>=1; } return ret; } }; template<int32_t id> struct ArbitraryBarrettModint{ static uint32_t _phi(uint32_t N){ uint32_t prime_fact=N; uint32_t ret=N; for(int i=2; i*i<prime_fact; i++){ if(prime_fact%i==0){ ret-=ret/i; while(prime_fact%i==0){ prime_fact/=i; } } } if(prime_fact!=1){ ret-=ret/prime_fact; } return ret; } static uint64_t N,Nr; static uint32_t inv_power; int64_t x; static void set_mod(uint32_t mod){ N=mod; Nr=(-1ULL)/N+1; inv_power=_phi(N)-1; assert(1<mod); assert(mod<(1<<30)); } uint32_t mod(){ return N; } int64_t _get_mod(uint64_t x){ uint64_t ret=((unsigned __int128)x*Nr)>>64; if(x-ret*N<0){ return x-(ret-1)*N; } return x-ret*N; } ArbitraryBarrettModint()noexcept{ x=0; } ArbitraryBarrettModint(int64_t val)noexcept{ x=((val%N)+N)%N; } uint64_t val()noexcept{ return x; } friend ostream &operator<<(ostream &os,ArbitraryBarrettModint &b){ return os<<b.val(); } ArbitraryBarrettModint operator+()noexcept{return *this;} ArbitraryBarrettModint operator-()noexcept{return ArbitraryBarrettModint()-(*this);} friend ArbitraryBarrettModint operator+(ArbitraryBarrettModint lhs,ArbitraryBarrettModint rhs)noexcept{ return ArbitraryBarrettModint(lhs)+=rhs; } friend ArbitraryBarrettModint operator-(ArbitraryBarrettModint lhs,ArbitraryBarrettModint rhs)noexcept{ return ArbitraryBarrettModint(lhs)-=rhs; } friend ArbitraryBarrettModint operator*(ArbitraryBarrettModint lhs,ArbitraryBarrettModint rhs)noexcept{ return ArbitraryBarrettModint(lhs)*=rhs; } friend ArbitraryBarrettModint operator/(ArbitraryBarrettModint lhs,ArbitraryBarrettModint rhs){ return ArbitraryBarrettModint(lhs)/=rhs; } ArbitraryBarrettModint operator+=(ArbitraryBarrettModint rhs)noexcept{ x+=rhs.x; if(x>=N)x-=N; return *this; } ArbitraryBarrettModint operator-=(ArbitraryBarrettModint rhs)noexcept{ x-=rhs.x; if(x<0)x+=N; return *this; } ArbitraryBarrettModint operator*=(ArbitraryBarrettModint rhs)noexcept{ x=_get_mod(x*rhs.x); return *this; } ArbitraryBarrettModint operator/=(ArbitraryBarrettModint rhs){ (*this)*=rhs.inv(); return *this; } ArbitraryBarrettModint& operator++(){ (*this)+=1; return *this; } ArbitraryBarrettModint& operator--(){ (*this)-=1; return *this; } ArbitraryBarrettModint operator++(int){ (*this)+=1; return *this; } ArbitraryBarrettModint operator--(int){ (*this)-=1; return *this; } bool operator==(ArbitraryBarrettModint rhs)noexcept{ return (x>=N?x-N:x)==(rhs.x>=N?rhs.x-N:rhs.x); } bool operator!=(ArbitraryBarrettModint rhs)noexcept{ return (x>=N?x-N:x)!=(rhs.x>=N?rhs.x-N:rhs.x); } ArbitraryBarrettModint inv(){ ArbitraryBarrettModint ret=(*this).pow(inv_power); assert(ret*(*this)==1); return ret; } ArbitraryBarrettModint pow(uint64_t x)noexcept{ ArbitraryBarrettModint ret=1; ArbitraryBarrettModint bin=(*this); while(x){ if(x&1)ret*=bin; bin*=bin; x>>=1; } return ret; } }; template<int id>uint64_t ArbitraryBarrettModint<id>::N; template<int id>uint64_t ArbitraryBarrettModint<id>::Nr; template<int id>uint32_t ArbitraryBarrettModint<id>::inv_power; template<uint32_t N> inline void print(BarrettModint<N> a){ cout << a; } template<int32_t id> inline void print(ArbitraryBarrettModint<id> a){ cout << a; } #line 4 "Verify/verify-yuki/yuki_1092-barrett.test.cpp" using mint=ArbitraryBarrettModint<0>; void solve(){ LL(P,n); VEC(ll,A,n); STR(S); mint::set_mod(P); mint ans=A[0]; rep(i,n-1){ if(S[i]=='+'){ ans+=A[i+1]; } if(S[i]=='-'){ ans-=A[i+1]; } if(S[i]=='*'){ ans*=A[i+1]; } if(S[i]=='/'){ ans/=A[i+1]; } } out(ans); } int main(){ solve(); return 0; }