結果

問題 No.1092 modular arithmetic
ユーザー AkabaEriAkabaEri
提出日時 2020-07-27 20:34:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 741 bytes
コンパイル時間 1,530 ms
コンパイル使用メモリ 164,768 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-11 05:58:44
合計ジャッジ時間 8,944 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,380 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 17 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 5 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 20 ms
4,380 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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;


int main(){
  ll p,n;
  cin >> p >> n;
  ll a[n];
  rep(i,n)cin >> a[i];
  ll up=a[0],down=1;
  for(int i=1;i<n;i++){
    char g;
    cin >> g;
    if(g=='+'){up+=down*a[i];}
    else if(g=='-'){up-=down*a[i];}
    else if(g=='*'){up*=a[i];}
    else if(g=='/'){down*=a[i];}

    if(__gcd(up,down)!=1){
      ll q=__gcd(up,down);
      up/=q;
      down/=q;
    } 
  }
  while(up<0){up+=p;}
  cout << up/down << endl;
}
0