結果

問題 No.1092 modular arithmetic
ユーザー motmot
提出日時 2020-07-02 18:49:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 352 ms / 2,000 ms
コード長 1,109 bytes
コンパイル時間 2,295 ms
コンパイル使用メモリ 82,872 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-13 04:05:26
合計ジャッジ時間 10,311 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 43 ms
4,480 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 117 ms
4,372 KB
testcase_04 AC 108 ms
4,372 KB
testcase_05 AC 106 ms
4,388 KB
testcase_06 AC 87 ms
4,376 KB
testcase_07 AC 79 ms
4,368 KB
testcase_08 AC 101 ms
4,372 KB
testcase_09 AC 109 ms
4,372 KB
testcase_10 AC 80 ms
4,372 KB
testcase_11 AC 105 ms
4,372 KB
testcase_12 AC 97 ms
4,368 KB
testcase_13 AC 15 ms
4,368 KB
testcase_14 AC 16 ms
4,388 KB
testcase_15 AC 5 ms
4,368 KB
testcase_16 AC 13 ms
4,372 KB
testcase_17 AC 17 ms
4,372 KB
testcase_18 AC 146 ms
4,372 KB
testcase_19 AC 88 ms
4,372 KB
testcase_20 AC 150 ms
4,368 KB
testcase_21 AC 116 ms
4,368 KB
testcase_22 AC 140 ms
4,372 KB
testcase_23 AC 352 ms
4,368 KB
testcase_24 AC 66 ms
4,368 KB
testcase_25 AC 248 ms
4,368 KB
testcase_26 AC 200 ms
4,372 KB
testcase_27 AC 43 ms
4,372 KB
testcase_28 AC 249 ms
4,368 KB
testcase_29 AC 291 ms
4,372 KB
testcase_30 AC 194 ms
4,372 KB
testcase_31 AC 31 ms
4,372 KB
testcase_32 AC 234 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll P, N;
  cin>>P>>N;
  ll A[N];
  for(int i=0;i<N;++i) cin>>A[i];
  string S;
  cin>>S;
  ll ans = A[0]%P;
  ll h;
  ll two;
  ll tmp;
  for(int i=0;i<S.size();++i){
    if(S[i]=='+'){
      ans += A[i+1];
      ans %= P;
    }
    if(S[i]=='-'){
      ans -= A[i+1];
      ans = (ans + P)%P;
    }
    if(S[i]=='*'){
      ans *= A[i+1];
      ans %= P;
    }
    if(S[i]=='/'){
      h = P-2;
      while(h>0){
        two = 1;
        tmp = A[i+1];
        while(2*two<=h){
          two *= 2;
          tmp *= tmp;
          tmp %= P;
        }
        h -= two;
        ans *= tmp;
        ans %= P;
      }
    }
  }
  cout<<ans<<endl;
}
0