結果

問題 No.2336 Do you like typical problems?
ユーザー SSRSSSRS
提出日時 2022-08-22 04:59:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 928 bytes
コンパイル時間 2,073 ms
コンパイル使用メモリ 165,380 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2024-04-15 12:12:11
合計ジャッジ時間 8,578 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,760 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 522 ms
6,940 KB
testcase_09 AC 517 ms
6,944 KB
testcase_10 AC 516 ms
6,940 KB
testcase_11 AC 518 ms
6,940 KB
testcase_12 AC 515 ms
6,944 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long modpow(long long a, long long b){
	long long ans = 1;
	while (b > 0){
		if (b % 2 == 1){
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		b /= 2;
	}
	return ans;
}
long long modinv(long long a){
	return modpow(a, MOD - 2);
}
int main(){
  int N;
  cin >> N;
  vector<int> B(N), C(N);
  for (int i = 0; i < N; i++){
    cin >> B[i] >> C[i];
    C[i]++;
  }
  long long ans = 0;
  for (int i = 0; i < N; i++){
    for (int j = i + 1; j < N; j++){
      long long p = 1;
      int mn = max(B[i], B[j]);
      int mx = min(C[i], C[j]);
      if (mn < mx){
        p -= (mx - mn) * modinv((long long) (C[i] - B[i]) * (C[j] - B[j]) % MOD) % MOD;
        p += MOD;
        p %= MOD;
      }
      ans += p * modinv(2) % MOD;
    }
  }
  ans %= MOD;
  for (int i = 1; i <= N; i++){
    ans *= i;
    ans %= MOD;
  }
  cout << ans << endl;
}
0