結果

問題 No.2615 ペアの作り方
ユーザー Yaowei LyuYaowei Lyu
提出日時 2024-01-26 21:34:38
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,037 bytes
コンパイル時間 5,082 ms
コンパイル使用メモリ 319,296 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-28 07:45:11
合計ジャッジ時間 6,171 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>

#ifndef ONLINE_JUDGE
#include "debug.h"  // https://github.com/Heltion/debug.h/blob/main/debug.h
#else
#define debug(...) (void)417
#endif

using i64 = int64_t;
using mint = atcoder::modint998244353;
int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  for (int& xi : x) { cin >> xi; }
  for (int& yi : y) { cin >> yi; }
  ranges::sort(x);
  ranges::sort(y, greater());
  vector<int> a, b, c, d;
  for (int i = 0; i < n; i += 1) {
    if (x[i] < y[i]) {
      a.push_back(x[i]);
      b.push_back(y[i]);
    } else {
      c.push_back(x[i]);
      d.push_back(y[i]);
    }
  }
  auto f = [&](vector<int> a, vector<int> b) {
    mint res = 1;
    ranges::sort(a);
    ranges::sort(b);
    for (int i = 0, j = 0; i < ssize(b); i += 1) {
      while (j < ssize(a) and a[j] < b[i]) { j += 1; }
      res *= j - i;
    }
    return res;
  };
  cout << (f(a, b) * f(d, c)).val();
}
0