結果

問題 No.1359 [Zelkova 3rd Tune] 四人セゾン
ユーザー kyo1
提出日時 2021-01-25 15:06:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 511 ms / 2,000 ms
コード長 1,272 bytes
コンパイル時間 1,848 ms
コンパイル使用メモリ 197,984 KB
最終ジャッジ日時 2025-01-18 08:07:08
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 75
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

template <typename T>
int pow(int x, T n, int mod = std::numeric_limits<int>::max()) {
  int res = 1;
  while (n > 0) {
    if (n & 1) res = static_cast<int64_t>(res) * static_cast<int64_t>(x) % mod;
    x = static_cast<int64_t>(x) * static_cast<int64_t>(x) % mod;
    n >>= 1;
  }
  return res;
}

template <typename T>
int64_t pow(int64_t x, T n, int64_t mod = std::numeric_limits<int64_t>::max()) {
  int64_t res = 1;
  while (n > 0) {
    if (n & 1) res = static_cast<__int128>(res) * static_cast<__int128>(x) % mod;
    x = static_cast<__int128>(x) * static_cast<__int128>(x) % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K, M;
  cin >> N >> K >> M;
  vector<int> A(N), B(N), C(N), D(N);
  for (auto &&e : A) {
    cin >> e;
  }
  for (auto &&e : B) {
    cin >> e;
  }
  for (auto &&e : C) {
    cin >> e;
  }
  for (auto &&e : D) {
    cin >> e;
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  sort(D.begin(), D.end());
  int res = 0;
  for (int i = 0; i < N; i++) {
    res += pow(max({A[i], B[i], C[i], D[i]}) - min({A[i], B[i], C[i], D[i]}), K, M);
    res %= M;
  }
  cout << res << '\n';
  return 0;
}
0