結果

問題 No.1359 [Zelkova 3rd Tune] 四人セゾン
ユーザー tkmst201tkmst201
提出日時 2021-01-23 15:34:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 289 ms / 2,000 ms
コード長 4,189 bytes
コンパイル時間 2,913 ms
コンパイル使用メモリ 205,384 KB
実行使用メモリ 6,500 KB
最終ジャッジ日時 2023-08-29 05:10:03
合計ジャッジ時間 27,505 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 147 ms
4,880 KB
testcase_04 AC 142 ms
4,756 KB
testcase_05 AC 129 ms
4,736 KB
testcase_06 AC 132 ms
4,744 KB
testcase_07 AC 192 ms
5,388 KB
testcase_08 AC 195 ms
5,544 KB
testcase_09 AC 55 ms
4,376 KB
testcase_10 AC 55 ms
4,380 KB
testcase_11 AC 252 ms
5,968 KB
testcase_12 AC 246 ms
6,068 KB
testcase_13 AC 156 ms
4,920 KB
testcase_14 AC 158 ms
4,932 KB
testcase_15 AC 142 ms
4,748 KB
testcase_16 AC 140 ms
4,752 KB
testcase_17 AC 263 ms
6,068 KB
testcase_18 AC 269 ms
6,068 KB
testcase_19 AC 227 ms
5,788 KB
testcase_20 AC 230 ms
5,784 KB
testcase_21 AC 272 ms
5,708 KB
testcase_22 AC 253 ms
5,868 KB
testcase_23 AC 167 ms
4,892 KB
testcase_24 AC 189 ms
5,048 KB
testcase_25 AC 30 ms
4,380 KB
testcase_26 AC 26 ms
4,384 KB
testcase_27 AC 87 ms
4,380 KB
testcase_28 AC 105 ms
4,376 KB
testcase_29 AC 106 ms
4,416 KB
testcase_30 AC 116 ms
4,404 KB
testcase_31 AC 155 ms
4,632 KB
testcase_32 AC 144 ms
4,600 KB
testcase_33 AC 113 ms
4,504 KB
testcase_34 AC 108 ms
4,376 KB
testcase_35 AC 145 ms
4,692 KB
testcase_36 AC 142 ms
4,680 KB
testcase_37 AC 49 ms
4,380 KB
testcase_38 AC 29 ms
4,380 KB
testcase_39 AC 24 ms
4,380 KB
testcase_40 AC 24 ms
4,376 KB
testcase_41 AC 51 ms
4,380 KB
testcase_42 AC 50 ms
4,376 KB
testcase_43 AC 41 ms
4,380 KB
testcase_44 AC 268 ms
5,972 KB
testcase_45 AC 109 ms
4,412 KB
testcase_46 AC 38 ms
4,376 KB
testcase_47 AC 189 ms
5,184 KB
testcase_48 AC 178 ms
5,212 KB
testcase_49 AC 181 ms
5,216 KB
testcase_50 AC 138 ms
4,656 KB
testcase_51 AC 8 ms
4,380 KB
testcase_52 AC 238 ms
5,712 KB
testcase_53 AC 266 ms
6,324 KB
testcase_54 AC 282 ms
6,232 KB
testcase_55 AC 282 ms
6,184 KB
testcase_56 AC 280 ms
6,500 KB
testcase_57 AC 281 ms
6,320 KB
testcase_58 AC 274 ms
6,332 KB
testcase_59 AC 279 ms
6,268 KB
testcase_60 AC 277 ms
6,276 KB
testcase_61 AC 263 ms
6,232 KB
testcase_62 AC 283 ms
6,216 KB
testcase_63 AC 282 ms
6,236 KB
testcase_64 AC 284 ms
6,236 KB
testcase_65 AC 281 ms
6,240 KB
testcase_66 AC 277 ms
6,252 KB
testcase_67 AC 289 ms
6,272 KB
testcase_68 AC 276 ms
6,240 KB
testcase_69 AC 260 ms
6,280 KB
testcase_70 AC 263 ms
6,320 KB
testcase_71 AC 252 ms
6,396 KB
testcase_72 AC 282 ms
6,388 KB
testcase_73 AC 278 ms
6,324 KB
testcase_74 AC 275 ms
6,236 KB
testcase_75 AC 278 ms
6,332 KB
testcase_76 AC 274 ms
6,328 KB
testcase_77 AC 277 ms
6,248 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