結果

問題 No.2615 ペアの作り方
ユーザー nono00
提出日時 2024-01-26 21:29:06
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 3,635 bytes
コンパイル時間 3,406 ms
コンパイル使用メモリ 266,572 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-09-28 07:40:59
合計ジャッジ時間 4,753 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
#include <iostream>
namespace nono {
namespace internal {
constexpr bool is_prime(unsigned long long n) {
for (unsigned long long i = 2; i * i <= n; i++) {
if (n % i == 0) return false;
}
return true;
}
} // namespace internal
template <unsigned long long MOD = 998244353>
class Modint {
public:
static_assert(internal::is_prime(MOD));
constexpr Modint(unsigned long long value = 0): value_(value % MOD) {}
constexpr Modint pow(long long exp) const {
Modint result(1);
Modint base(*this);
while (exp > 0) {
if (exp & 1) {
result *= base;
}
base *= base;
exp >>= 1;
}
return result;
}
constexpr Modint inv() const {
return pow(MOD - 2);
}
void set(unsigned long long value) {
if (value >= MOD) value %= MOD;
value_ = value;
}
unsigned long long get() const {
return value_;
}
friend constexpr bool operator==(const Modint lhs, const Modint rhs) {
return lhs.value_ == rhs.value_;
}
constexpr Modint& operator+=(const Modint other) {
this->value_ += other.value_;
if (this->value_ >= MOD) this->value_ -= MOD;
return *this;
}
constexpr Modint& operator-=(const Modint other) {
this->value_ += MOD - other.value_;
if (this->value_ >= MOD) this->value_ -= MOD;
return *this;
}
constexpr Modint& operator*=(const Modint other) {
this->value_ *= other.value_;
if (this->value_ >= MOD) this->value_ %= MOD;
return *this;
}
constexpr Modint& operator/=(const Modint other) {
return *this *= other.inv();
}
constexpr friend Modint operator+(const Modint lhs, const Modint rhs) {
return Modint(lhs) += rhs;
}
constexpr friend Modint operator-(const Modint lhs, const Modint rhs) {
return Modint(lhs) -= rhs;
}
constexpr friend Modint operator*(const Modint lhs, const Modint rhs) {
return Modint(lhs) *= rhs;
}
constexpr friend Modint operator/(const Modint lhs, const Modint rhs) {
return Modint(lhs) /= rhs;
}
friend std::istream& operator>>(std::istream& stream, Modint& mint) {
unsigned long long value;
stream >> value;
mint.set(value);
return stream;
}
friend std::ostream& operator<<(std::ostream& stream, Modint mint) {
stream << mint.get();
return stream;
}
private:
unsigned long long value_;
};
using Modint998244353 = Modint<998244353>;
using Modint1000000007 = Modint<1000000007>;
} // namespace nono
void solve() {
using Mint = nono::Modint998244353;
int n;
std::cin >> n;
std::vector<long long> x(n), y(n);
for (int i = 0; i < n; i++) std::cin >> x[i];
for (int i = 0; i < n; i++) std::cin >> y[i];
std::vector<long long> z;
for (int i = 0; i < n; i++) {
z.push_back(x[i]);
z.push_back(y[i]);
}
std::ranges::sort(z);
std::set<long long> s;
for (int i = 0; i < n; i++) {
s.insert(z[i]);
}
int a = 0, b = 0;
for (int i = 0; i < n; i++) {
if (s.contains(x[i])) a++;
if (s.contains(y[i])) b++;
}
auto fact = [](int n) {
Mint ans = 1;
for (int i = 1; i <= n; i++) ans *= i;
return ans;
};
std::cout << fact(a) * fact(b) << '\n';
}
int main() {
std::cin.tie(0)->sync_with_stdio(0);
std::cout << std::fixed << std::setprecision(16);
int t = 1;
while (t--) solve();
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0