結果

問題 No.1359 [Zelkova 3rd Tune] 四人セゾン
ユーザー 👑 emthrmemthrm
提出日時 2021-01-22 22:01:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 245 ms / 2,000 ms
コード長 4,696 bytes
コンパイル時間 2,671 ms
コンパイル使用メモリ 208,172 KB
実行使用メモリ 7,220 KB
最終ジャッジ日時 2023-08-27 19:08:40
合計ジャッジ時間 20,275 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 124 ms
5,136 KB
testcase_04 AC 123 ms
5,060 KB
testcase_05 AC 113 ms
5,164 KB
testcase_06 AC 113 ms
5,216 KB
testcase_07 AC 169 ms
5,904 KB
testcase_08 AC 168 ms
5,992 KB
testcase_09 AC 47 ms
4,380 KB
testcase_10 AC 47 ms
4,380 KB
testcase_11 AC 217 ms
6,492 KB
testcase_12 AC 218 ms
6,488 KB
testcase_13 AC 139 ms
5,428 KB
testcase_14 AC 140 ms
5,380 KB
testcase_15 AC 122 ms
4,804 KB
testcase_16 AC 123 ms
4,840 KB
testcase_17 AC 230 ms
6,800 KB
testcase_18 AC 229 ms
6,700 KB
testcase_19 AC 198 ms
6,196 KB
testcase_20 AC 198 ms
6,256 KB
testcase_21 AC 217 ms
6,388 KB
testcase_22 AC 215 ms
6,604 KB
testcase_23 AC 147 ms
5,336 KB
testcase_24 AC 151 ms
5,336 KB
testcase_25 AC 24 ms
4,380 KB
testcase_26 AC 24 ms
4,380 KB
testcase_27 AC 76 ms
4,380 KB
testcase_28 AC 77 ms
4,384 KB
testcase_29 AC 95 ms
4,640 KB
testcase_30 AC 95 ms
4,532 KB
testcase_31 AC 125 ms
5,120 KB
testcase_32 AC 126 ms
5,120 KB
testcase_33 AC 94 ms
4,624 KB
testcase_34 AC 92 ms
4,672 KB
testcase_35 AC 121 ms
5,140 KB
testcase_36 AC 122 ms
5,304 KB
testcase_37 AC 25 ms
4,380 KB
testcase_38 AC 25 ms
4,376 KB
testcase_39 AC 21 ms
4,376 KB
testcase_40 AC 21 ms
4,380 KB
testcase_41 AC 44 ms
4,376 KB
testcase_42 AC 44 ms
4,376 KB
testcase_43 AC 36 ms
4,380 KB
testcase_44 AC 230 ms
6,724 KB
testcase_45 AC 96 ms
4,620 KB
testcase_46 AC 32 ms
4,380 KB
testcase_47 AC 164 ms
5,640 KB
testcase_48 AC 155 ms
5,640 KB
testcase_49 AC 156 ms
5,664 KB
testcase_50 AC 118 ms
4,856 KB
testcase_51 AC 7 ms
4,376 KB
testcase_52 AC 204 ms
6,488 KB
testcase_53 AC 235 ms
6,960 KB
testcase_54 AC 244 ms
7,004 KB
testcase_55 AC 241 ms
7,020 KB
testcase_56 AC 243 ms
7,056 KB
testcase_57 AC 243 ms
6,960 KB
testcase_58 AC 244 ms
6,964 KB
testcase_59 AC 242 ms
6,916 KB
testcase_60 AC 239 ms
6,988 KB
testcase_61 AC 228 ms
6,916 KB
testcase_62 AC 242 ms
6,952 KB
testcase_63 AC 243 ms
7,028 KB
testcase_64 AC 244 ms
7,000 KB
testcase_65 AC 240 ms
6,964 KB
testcase_66 AC 241 ms
7,220 KB
testcase_67 AC 245 ms
6,920 KB
testcase_68 AC 238 ms
6,908 KB
testcase_69 AC 226 ms
7,056 KB
testcase_70 AC 227 ms
6,968 KB
testcase_71 AC 221 ms
6,960 KB
testcase_72 AC 244 ms
6,988 KB
testcase_73 AC 237 ms
6,904 KB
testcase_74 AC 236 ms
7,044 KB
testcase_75 AC 236 ms
6,988 KB
testcase_76 AC 234 ms
7,028 KB
testcase_77 AC 236 ms
6,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

struct ModInt {
  unsigned val;
  ModInt(): val(0) {}
  ModInt(long long x) : val(x >= 0 ? x % mod() : x % mod() + mod()) {}
  static int get_mod() { return mod(); }
  static void set_mod(int divisor) { mod() = divisor; }
  ModInt pow(long long exponent) const {
    ModInt tmp = *this, res = 1;
    while (exponent > 0) {
      if (exponent & 1) res *= tmp;
      tmp *= tmp;
      exponent >>= 1;
    }
    return res;
  }
  ModInt &operator+=(const ModInt &x) { if((val += x.val) >= mod()) val -= mod(); return *this; }
  ModInt &operator-=(const ModInt &x) { if((val += mod() - x.val) >= mod()) val -= mod(); return *this; }
  ModInt &operator*=(const ModInt &x) { val = static_cast<unsigned long long>(val) * x.val % mod(); return *this; }
  ModInt &operator/=(const ModInt &x) {
    // assert(std::__gcd(static_cast<int>(x.val), mod()) == 1);
    unsigned a = x.val, b = mod(); int u = 1, v = 0;
    while (b) {
      unsigned tmp = a / b;
      std::swap(a -= tmp * b, b);
      std::swap(u -= tmp * v, v);
    }
    return *this *= u;
  }
  bool operator==(const ModInt &x) const { return val == x.val; }
  bool operator!=(const ModInt &x) const { return val != x.val; }
  bool operator<(const ModInt &x) const { return val < x.val; }
  bool operator<=(const ModInt &x) const { return val <= x.val; }
  bool operator>(const ModInt &x) const { return val > x.val; }
  bool operator>=(const ModInt &x) const { return val >= x.val; }
  ModInt &operator++() { if (++val == mod()) val = 0; return *this; }
  ModInt operator++(int) { ModInt res = *this; ++*this; return res; }
  ModInt &operator--() { val = (val == 0 ? mod() : val) - 1; return *this; }
  ModInt operator--(int) { ModInt res = *this; --*this; return res; }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { return ModInt(val ? mod() - val : 0); }
  ModInt operator+(const ModInt &x) const { return ModInt(*this) += x; }
  ModInt operator-(const ModInt &x) const { return ModInt(*this) -= x; }
  ModInt operator*(const ModInt &x) const { return ModInt(*this) *= x; }
  ModInt operator/(const ModInt &x) const { return ModInt(*this) /= x; }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &x) { return os << x.val; }
  friend std::istream &operator>>(std::istream &is, ModInt &x) { long long val; is >> val; x = ModInt(val); return is; }
private:
  static int &mod() { static int divisor = 0; return divisor; }
};
namespace std { ModInt abs(const ModInt &x) { return x; } }
struct Combinatorics {
  int val;  // "val!" and "mod" must be disjoint.
  std::vector<ModInt> fact, fact_inv, inv;
  Combinatorics(int val = 10000000) : val(val), fact(val + 1), fact_inv(val + 1), inv(val + 1) {
    fact[0] = 1;
    for (int i = 1; i <= val; ++i) fact[i] = fact[i - 1] * i;
    fact_inv[val] = ModInt(1) / fact[val];
    for (int i = val; i > 0; --i) fact_inv[i - 1] = fact_inv[i] * i;
    for (int i = 1; i <= val; ++i) inv[i] = fact[i - 1] * fact_inv[i];
  }
  ModInt nCk(int n, int k) const {
    if (n < 0 || n < k || k < 0) return 0;
    assert(n <= val && k <= val);
    return fact[n] * fact_inv[k] * fact_inv[n - k];
  }
  ModInt nPk(int n, int k) const {
    if (n < 0 || n < k || k < 0) return 0;
    assert(n <= val);
    return fact[n] * fact_inv[n - k];
  }
  ModInt nHk(int n, int k) const {
    if (n < 0 || k < 0) return 0;
    return k == 0 ? 1 : nCk(n + k - 1, k);
  }
};

int main() {
  int n, k, m; cin >> n >> k >> m;
  ModInt::set_mod(m);
  vector<vector<int>> peah(4, vector<int>(n)); REP(i, 4) REP(j, n) cin >> peah[i][j];
  REP(i, 4) sort(ALL(peah[i]));
  ModInt ans = 0;
  REP(j, n) {
    int mn = 1000000000, mx = 0;
    REP(i, 4) {
      chmin(mn, peah[i][j]);
      chmax(mx, peah[i][j]);
    }
    ans += ModInt(mx - mn).pow(k);
  }
  cout << ans << '\n';
  return 0;
}
0