Submission #51166760
Source Code Expand
/*
Author: Denys Smirnov
Time: 2024-03-12 00:23:36
*/
#include "bits/stdc++.h"
#include "atcoder/modint.hpp"
#ifdef DENDI239
#define D \
for (bool _flag_dendi239 = true; _flag_dendi239; _flag_dendi239 = false)
#else
#define D while (false)
#endif
using namespace std;
using Mint = atcoder::modint998244353;
Mint F(int n, Mint m) {
if (n == 1)
return 0;
// else if (n == 2)
// return m * (m - 1);
// else
// return m * (m - 1).pow(n - 1) - F(n - 1, m);
// m-1^n-1 - m-1^n-2 + ... +- m-1 | * (m-1 + 1)
// m-1^n + m-1^n-1 -m-1^n-1 - m-1^n-2 + ... +- m-1^2 +- m-1
// ------- ------- ------- -----
// m-1^n +- m-1
// m-1(m-1^n-1 +- 1) / m
return (m - 1) * (m.pow(n - 1) - Mint(-1).pow(n - 1));
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m_int;
cin >> n >> m_int;
Mint m(m_int);
if (n == 1) {
cout << m.val() << "\n";
return 0;
}
Mint res = 0;
for (size_t i = 0; i + 1 < n; ++i) {
if (i % 2) {
res -= m * (m - 1).pow(n - 1 - i);
} else {
res += m * (m - 1).pow(n - 1 - i);
}
}
cout << res.val() << "\n";
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Distinct Adjacent |
| User | dendi239 |
| Language | C++ 20 (gcc 12.2) |
| Score | 475 |
| Code Size | 1289 Byte |
| Status | AC |
| Exec Time | 68 ms |
| Memory | 3648 KiB |
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:51:28: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
51 | for (size_t i = 0; i + 1 < n; ++i) {
| ~~~~~~^~~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 475 / 475 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | hand_01.txt, hand_02.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| hand_01.txt | AC | 30 ms | 3648 KiB |
| hand_02.txt | AC | 20 ms | 3436 KiB |
| random_01.txt | AC | 68 ms | 3448 KiB |
| random_02.txt | AC | 22 ms | 3448 KiB |
| random_03.txt | AC | 13 ms | 3460 KiB |
| random_04.txt | AC | 22 ms | 3648 KiB |
| random_05.txt | AC | 68 ms | 3524 KiB |
| random_06.txt | AC | 62 ms | 3532 KiB |
| random_07.txt | AC | 16 ms | 3420 KiB |
| random_08.txt | AC | 4 ms | 3528 KiB |
| random_09.txt | AC | 67 ms | 3592 KiB |
| random_10.txt | AC | 7 ms | 3596 KiB |
| random_11.txt | AC | 22 ms | 3420 KiB |
| random_12.txt | AC | 2 ms | 3648 KiB |
| random_13.txt | AC | 67 ms | 3612 KiB |
| random_14.txt | AC | 57 ms | 3420 KiB |
| random_15.txt | AC | 60 ms | 3420 KiB |
| random_16.txt | AC | 54 ms | 3416 KiB |
| random_17.txt | AC | 1 ms | 3528 KiB |
| random_18.txt | AC | 67 ms | 3424 KiB |
| random_19.txt | AC | 1 ms | 3612 KiB |
| sample_01.txt | AC | 1 ms | 3420 KiB |
| sample_02.txt | AC | 1 ms | 3528 KiB |
| sample_03.txt | AC | 67 ms | 3528 KiB |