結果

問題 No.2336 Do you like typical problems?
ユーザー SSRSSSRS
提出日時 2021-11-23 14:18:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,026 bytes
コンパイル時間 1,968 ms
コンパイル使用メモリ 168,796 KB
実行使用メモリ 13,884 KB
最終ジャッジ日時 2024-04-15 12:11:35
合計ジャッジ時間 5,909 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,884 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 18 ms
6,944 KB
testcase_09 AC 17 ms
6,944 KB
testcase_10 AC 18 ms
6,944 KB
testcase_11 AC 18 ms
6,940 KB
testcase_12 AC 18 ms
6,940 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;
const long long HALF = 499122177;
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]++;
  }
  vector<long long> D(N);
  for (int i = 0; i < N; i++){
    D[i] = modinv(C[i] - B[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) * D[i] % MOD * D[j] % MOD;
        if (p < 0){
          p += MOD;
        }
      }
      ans += p * HALF % MOD;
    }
  }
  ans %= MOD;
  for (int i = 1; i <= N; i++){
    ans *= i;
    ans %= MOD;
  }
  cout << ans << endl;
}
0