結果
問題 | No.2875 What is My Rank? |
ユーザー |
|
提出日時 | 2024-10-16 00:10:58 |
言語 | C# (.NET 8.0.404) |
結果 |
AC
|
実行時間 | 431 ms / 2,000 ms |
コード長 | 1,925 bytes |
コンパイル時間 | 8,200 ms |
コンパイル使用メモリ | 167,384 KB |
実行使用メモリ | 216,664 KB |
最終ジャッジ日時 | 2024-10-16 00:11:16 |
合計ジャッジ時間 | 17,777 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (99 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System;using static System.Console;using System.Linq;using System.Collections.Generic;class Program{static int NN => int.Parse(ReadLine());static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();public static void Main(){Solve();}static void Solve(){var n = NN;var map = NArr(n);WriteLine(Rank(n, map));}static long Rank(int n, int[][] map){var mod = 998_244_353;var ans = 1L;var len = map[0][1] - map[0][0] + 1L;for (var i = 1; i < n; ++i){var pa = Exp(len * (map[i][1] - map[i][0] + 1), mod - 2, mod);var overlen = Math.Max(0L, map[i][1] - Math.Max(map[i][0] - 1, map[0][1]));var underlen = Math.Max(0L, Math.Min(map[0][1] + 1, map[i][0]) - map[0][0]);var samelen = Math.Max(0L, Math.Min(map[0][1], map[i][1]) - Math.Max(map[0][0], map[i][0]));var ch = 0L;if (map[0][1] < map[i][1]){ch += len * overlen % mod;}ch += samelen * (samelen + 1) / 2 % mod;if (map[0][0] < map[i][0]){ch += underlen * (map[i][1] - map[i][0] + 1) % mod;}ch += mod - overlen * underlen % mod;ans = (ans + pa * (ch % mod) % mod) % mod;}return ans;}static long Exp(long n, long p, int mod){long _n = n % mod;var _p = p;var result = 1L;if ((_p & 1) == 1) result *= _n;while (_p > 0){_n = _n * _n % mod;_p >>= 1;if ((_p & 1) == 1) result = result * _n % mod;}return result;}}