結果

問題 No.1359 [Zelkova 3rd Tune] 四人セゾン
ユーザー tkmst201tkmst201
提出日時 2021-01-23 15:34:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 274 ms / 2,000 ms
コード長 4,189 bytes
コンパイル時間 2,356 ms
コンパイル使用メモリ 207,620 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-09 20:30:34
合計ジャッジ時間 23,070 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 154 ms
6,944 KB
testcase_04 AC 129 ms
6,940 KB
testcase_05 AC 122 ms
6,940 KB
testcase_06 AC 119 ms
6,944 KB
testcase_07 AC 178 ms
6,940 KB
testcase_08 AC 181 ms
6,940 KB
testcase_09 AC 49 ms
6,940 KB
testcase_10 AC 52 ms
6,940 KB
testcase_11 AC 229 ms
6,944 KB
testcase_12 AC 232 ms
6,940 KB
testcase_13 AC 149 ms
6,940 KB
testcase_14 AC 150 ms
6,940 KB
testcase_15 AC 129 ms
6,940 KB
testcase_16 AC 135 ms
6,944 KB
testcase_17 AC 242 ms
6,940 KB
testcase_18 AC 259 ms
6,940 KB
testcase_19 AC 220 ms
6,944 KB
testcase_20 AC 223 ms
6,940 KB
testcase_21 AC 239 ms
6,944 KB
testcase_22 AC 242 ms
6,940 KB
testcase_23 AC 158 ms
6,944 KB
testcase_24 AC 153 ms
6,940 KB
testcase_25 AC 25 ms
6,940 KB
testcase_26 AC 25 ms
6,944 KB
testcase_27 AC 82 ms
6,944 KB
testcase_28 AC 80 ms
6,940 KB
testcase_29 AC 98 ms
6,944 KB
testcase_30 AC 100 ms
6,944 KB
testcase_31 AC 133 ms
6,940 KB
testcase_32 AC 134 ms
6,940 KB
testcase_33 AC 99 ms
6,940 KB
testcase_34 AC 107 ms
6,944 KB
testcase_35 AC 134 ms
6,940 KB
testcase_36 AC 130 ms
6,940 KB
testcase_37 AC 27 ms
6,944 KB
testcase_38 AC 27 ms
6,940 KB
testcase_39 AC 22 ms
6,940 KB
testcase_40 AC 23 ms
6,940 KB
testcase_41 AC 48 ms
6,940 KB
testcase_42 AC 48 ms
6,940 KB
testcase_43 AC 38 ms
6,944 KB
testcase_44 AC 245 ms
6,940 KB
testcase_45 AC 102 ms
6,940 KB
testcase_46 AC 36 ms
6,944 KB
testcase_47 AC 172 ms
6,940 KB
testcase_48 AC 160 ms
6,940 KB
testcase_49 AC 166 ms
6,940 KB
testcase_50 AC 126 ms
6,944 KB
testcase_51 AC 7 ms
6,940 KB
testcase_52 AC 221 ms
6,944 KB
testcase_53 AC 245 ms
6,940 KB
testcase_54 AC 266 ms
6,944 KB
testcase_55 AC 261 ms
6,940 KB
testcase_56 AC 260 ms
6,940 KB
testcase_57 AC 257 ms
6,940 KB
testcase_58 AC 261 ms
6,944 KB
testcase_59 AC 262 ms
6,940 KB
testcase_60 AC 251 ms
6,940 KB
testcase_61 AC 244 ms
6,948 KB
testcase_62 AC 258 ms
6,940 KB
testcase_63 AC 265 ms
6,940 KB
testcase_64 AC 264 ms
6,940 KB
testcase_65 AC 257 ms
6,944 KB
testcase_66 AC 258 ms
6,940 KB
testcase_67 AC 266 ms
6,940 KB
testcase_68 AC 255 ms
6,940 KB
testcase_69 AC 238 ms
6,944 KB
testcase_70 AC 241 ms
6,944 KB
testcase_71 AC 230 ms
6,940 KB
testcase_72 AC 258 ms
6,944 KB
testcase_73 AC 256 ms
6,940 KB
testcase_74 AC 255 ms
6,944 KB
testcase_75 AC 259 ms
6,940 KB
testcase_76 AC 274 ms
6,944 KB
testcase_77 AC 254 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

template<int ID>
struct RuntimeModInt {
public:
	using value_type = int;
	using calc_type = std::int_fast64_t;
	
private:
	value_type val_;
	static int & mod_() noexcept { static int M = 2; return M; }
	
public:
	RuntimeModInt(calc_type val = 0) : val_(val < 0 ? (val % mod() + mod()) % mod() : val % mod()) {}
	const value_type & val() const noexcept { return val_; }
	static void set_mod(int M) noexcept { assert(M > 0); mod_() = M; }
	static int mod() noexcept { return mod_(); }
	
	explicit operator bool() const noexcept { return val_; }
	bool operator !() const noexcept { return !static_cast<bool>(*this); }
	RuntimeModInt operator +() const noexcept { return RuntimeModInt(*this); }
	RuntimeModInt operator -() const noexcept { return RuntimeModInt(-val_); }
	RuntimeModInt operator ++(int) noexcept { RuntimeModInt res = *this; ++*this; return res; }
	RuntimeModInt operator --(int) noexcept { RuntimeModInt res = *this; --*this; return res; }
	RuntimeModInt & operator ++() noexcept { val_ = val_ + 1 == mod() ? 0 : val_ + 1; return *this; }
	RuntimeModInt & operator --() noexcept { val_ = val_ == 0 ? mod() - 1 : val_ - 1; return *this; }
	RuntimeModInt & operator +=(const RuntimeModInt & rhs) noexcept { val_ += val_ < mod() - rhs.val_ ? rhs.val_ : rhs.val_ - mod(); return *this; }
	RuntimeModInt & operator -=(const RuntimeModInt & rhs) noexcept { val_ += val_ >= rhs.val_ ? -rhs.val_ : mod() - rhs.val_; return *this; }
	RuntimeModInt & operator *=(const RuntimeModInt & rhs) noexcept { val_ = static_cast<calc_type>(val_) * rhs.val_ % mod(); return *this; }
	RuntimeModInt & operator /=(const RuntimeModInt & rhs) noexcept { return *this *= rhs.inv(); }
	friend RuntimeModInt operator +(const RuntimeModInt & lhs, const RuntimeModInt & rhs) noexcept { return RuntimeModInt(lhs) += rhs; }
	friend RuntimeModInt operator -(const RuntimeModInt & lhs, const RuntimeModInt & rhs) noexcept { return RuntimeModInt(lhs) -= rhs; }
	friend RuntimeModInt operator *(const RuntimeModInt & lhs, const RuntimeModInt & rhs) noexcept { return RuntimeModInt(lhs) *= rhs; }
	friend RuntimeModInt operator /(const RuntimeModInt & lhs, const RuntimeModInt & rhs) noexcept { return RuntimeModInt(lhs) /= rhs; }
	friend bool operator ==(const RuntimeModInt & lhs, const RuntimeModInt & rhs) noexcept { return lhs.val_ == rhs.val_; }
	friend bool operator !=(const RuntimeModInt & lhs, const RuntimeModInt & rhs) noexcept { return !(lhs == rhs); }
	friend std::ostream & operator <<(std::ostream & os, const RuntimeModInt & rhs) { return os << rhs.val_; }
	friend std::istream & operator >>(std::istream & is, RuntimeModInt & rhs) { calc_type x; is >> x; rhs = RuntimeModInt(x); return is; }
	
	RuntimeModInt pow(calc_type n) const noexcept {
		RuntimeModInt res = 1, x = val_;
		if (n < 0) { x = x.inv(); n = -n; }
		while (n) { if (n & 1) res *= x; x *= x; n >>= 1; }
		return res;
	}
	
	RuntimeModInt inv() const noexcept {
		value_type a = val_, a1 = 1, a2 = 0, b = mod(), b1 = 0, b2 = 1;
		while (b > 0) {
			value_type q = a / b, r = a % b;
			value_type nb1 = a1 - q * b1, nb2 = a2 - q * b2;
			a = b; b = r;
			a1 = b1; b1 = nb1;
			a2 = b2; b2 = nb2;
		}
		assert(a == 1);
		return a1;
	}
};
using mint = RuntimeModInt<-1>;

int main() {
	int N, K, M;
	cin >> N >> K >> M;
	vector<int> A[4];
	REP(i, 4) {
		A[i].resize(N);
		for (int & in : A[i]) scanf("%d", &in);
		sort(ALL(A[i]));
	}
	mint::set_mod(M);
	mint ans;
	REP(i, N) {
		int mn = INF, mx = -INF;
		REP(j, 4) {
			chmin(mn, A[j][i]);
			chmax(mx, A[j][i]);
		}
		ans += mint(mx - mn).pow(K);
	}
	cout << ans << endl;
}
0