結果

問題 No.988 N×Mマス計算(総和)
ユーザー k_kmhrk_kmhr
提出日時 2020-02-21 20:43:22
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 1,721 ms
コンパイル使用メモリ 170,744 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-06 07:29:25
合計ジャッジ時間 3,121 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n,m,k; cin>>n>>m>>k;
    char op; cin>>op;
    vector<ll> a(n), b(m);
    rep(i,m) cin>>b[i];
    rep(i,n) cin>>a[i];
    ll c=0;
    if(op=='+'){
        rep(i,n) {c+=m*a[i]; c%=k;}
        rep(i,m) {c+=n*b[i]; c%=k;}
        cout<<c<<endl;
    }else{
        ll sum_a=0, sum_b=0;
        rep(i,n) {sum_a+=a[i]; sum_a%=k;}
        rep(i,m) {sum_b+=b[i]; sum_b%=k;}
        cout<<(sum_b*sum_a)%k<<endl;
    }
    return 0;
}
0