結果

問題 No.1359 [Zelkova 3rd Tune] 四人セゾン
ユーザー zuminzumin
提出日時 2021-02-24 22:59:24
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 655 ms / 2,000 ms
コード長 1,002 bytes
コンパイル時間 752 ms
コンパイル使用メモリ 79,180 KB
実行使用メモリ 11,148 KB
最終ジャッジ日時 2024-09-24 23:46:38
合計ジャッジ時間 41,766 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 75
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
using ll=long long;

ll powmod(ll base,ll exp,ll mod){
    ll cnt=0;
    ll texp=exp;
    while(texp){cnt++;texp/=2;}
    vector<ll> dp(cnt,0);
    dp[0]=base%mod;
    for(ll i=1;i<cnt;i++){
        dp[i]=(dp[i-1]*dp[i-1])%mod;
    }
    ll ans=1;
    for(ll i=0;i<cnt;i++){
        if((exp>>i)&1){
            ans*=dp[i];
            ans%=mod;
        }
    }
    return ans;
}
int main(){
    ll n,k,m;
    cin>>n>>k>>m;
    vector<priority_queue<ll>> q(4);
    ll ans=0;

    for(int i=0;i<4;i++){
        for(int j=0;j<n;j++){
            ll tmp;
            cin>>tmp;
            q[i].push(tmp);
        }
    }

    for(int i=0;i<n;i++){
        ll ma=0,mi=1000000000;
        for(int j=0;j<4;j++){
            ll tmp=q[j].top();q[j].pop();
            ma=max(ma,tmp);
            mi=min(mi,tmp);
        }
        ans+=powmod(ma-mi,k,m);
        ans%=m;
    }
    cout<<ans<<endl;

    return 0;
}
0