結果
問題 | No.2452 Incline |
ユーザー | ochiaigawa |
提出日時 | 2023-09-01 23:24:50 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 99 ms / 2,000 ms |
コード長 | 1,101 bytes |
コンパイル時間 | 2,107 ms |
コンパイル使用メモリ | 202,848 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-09-01 23:24:55 |
合計ジャッジ時間 | 3,895 ms |
ジャッジサーバーID (参考情報) |
judge16 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 96 ms
4,380 KB |
testcase_04 | AC | 99 ms
4,380 KB |
testcase_05 | AC | 91 ms
4,380 KB |
testcase_06 | AC | 67 ms
4,380 KB |
testcase_07 | AC | 96 ms
4,380 KB |
testcase_08 | AC | 80 ms
4,380 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/modint> using namespace std; using mint = atcoder::modint998244353; void solve() { long long N, M, L, R; cin >> N >> M >> L >> R; mint ret = 0; ret += mint(L / (N - 1) + 1) * (R - L + 1); // (0 <= k <= L / (N - 1)) // L / (N - 1) + 1 <= k <= R / (N - 1) ret += mint(R - L + 1) * (R / (N - 1) - L / (N - 1)); if(R - (L / (N - 1) + 1) * (N - 1) >= 0) { mint r1 = (L / (N - 1) + 1) * (N - 1) - L; mint d1 = R / (N - 1) - L / (N - 1); ret -= r1 * d1; ret -= d1 * (d1 - 1) / 2 * (N - 1); } ret += mint((M - R) / (N - 1)) * (R - L + 1); // 1 <= k <= (M - R) / (N - 1) ret += mint(R - L + 1) * ((M - L) / (N - 1) - (M - R) / (N - 1)); if(((M - R) / (N - 1) + 1) * (N - 1) + L <= M) { mint r2 = R + ((M - R) / (N - 1) + 1) * (N - 1) - M; mint d2 = (M - L) / (N - 1) - (M - R) / (N - 1); ret -= r2 * d2; ret -= d2 * (d2 - 1) / 2 * (N - 1); } cout << ret.val() << '\n'; } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int T; cin >> T; while(T--) { solve(); } return 0; }