提出 #74713999
ソースコード 拡げる
#include<bits/extc++.h>
#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("avx,avx2")
#include<iostream>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define coutc "\033[48;5;196m\033[38;5;15m"
#define endc "\033[0m"
#define M(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) \
M(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep4(_, x, n, s) \
for (int _ = x; (s < 0) ? _ > n : _ < n; _ += s)
#define rep3(_, x, n) rep4(_, x, n, (x < n ? 1 : -1))
#define rep2(_, n) rep3(_, 0, n)
#define rep1(n) rep2(i, n)
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define mp make_pair
// #define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
// #define cin fin
// #define cout fout
// ifstream fin("word.in");
// ofstream fout("word.out");
const int inf = INT_MAX;
const int MOD = 998244353;
double PI = 4*atan(1);
#ifdef DEBUG
string to_string(char c) { return string({c}); }
// 7
template<class... Ts>
ostream& operator<<(ostream& o, tuple<Ts...> t) {
string s = "(";
apply([&](auto&&... r) {
((s += to_string(r) + ", "), ...); }, t);
return o << s.substr(0, len(s) - 2) + ")";
}
// 3
ostream& operator<<(ostream &o, pair<auto, auto> p) {
return o << "(" << p.fi << ", " << p.se << ")";
}
// 7
template<class C, class T = typename C::value_type,
typename std::enable_if<!std::is_same<C, std::string>
::value>::type* = nullptr>
ostream& operator<<(ostream &o, C c) {
for (auto e : c) o << setw(7) << right << e;
return o << endc << endl << coutc;
}
// 7
void debug(const auto &e, const auto &... r) {
cout << coutc << e;
((cout << " " << r), ..., (cout << endc << endl));
}
#else
#define debug(...)
#endif
map<string,int> mon;
map<int,string> inp;
ll pw[500005], iv[500005], fac[500005];
ll modpow(ll a, ll e) {
ll r = 1;
while (e) {
if (e & 1) r = r*a%MOD;
a = a*a%MOD;
e >>= 1;
}
return r;
}
void init() {
static bool ok = 0;
if (ok) return;
ok = 1;
int n = 500000;
pw[0] = 1;
fac[0] = 1;
int i = 1;
while (i <= n) {
pw[i] = pw[i - 1]*2%MOD;
fac[i] = fac[i - 1]*i%MOD;
i++;
}
iv[1] = 1;
i = 2;
while (i <= n) {
iv[i] = MOD - (MOD/i)*iv[MOD%i]%MOD;
i++;
}
}
void solve() {
int N, K;
cin >> N >> K;
ll sub = 0;
int mx = 0, cur = 0;
int i = 0;
while (i < K) {
int x;
cin >> x;
if (x > mx) mx = x;
if (x > cur) {
cur = x;
if (x < N) sub += pw[x - 1];
}
i++;
}
sub %= MOD;
int m = min(mx, N - 1);
ll det = (pw[m] - 1 - sub)%MOD;
if (det < 0) det += MOD;
ll tail = 0;
int x = mx + 1;
while (x < N) {
ll add = pw[x - 1]*(N - x)%MOD*iv[N - x + 1]%MOD;
tail += add;
if (tail >= MOD) tail -= MOD;
x++;
}
ll ans = fac[N - K]*(det + tail)%MOD;
cout << ans << endl;
}
void _main(int tc) {
init();
int T;
cin >> T;
while (T--) solve();
}
// 5
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
_main(0), exit(0);
int tc; cin >> tc; rep(i, tc) _main(i + 1);
}
提出情報
| 提出日時 |
|
| 問題 |
B - Not High Element |
| ユーザ |
zaahir |
| 言語 |
C++23 (GCC 15.2.0) |
| 得点 |
700 |
| コード長 |
3880 Byte |
| 結果 |
AC |
| 実行時間 |
26 ms |
| メモリ |
15468 KiB |
コンパイルエラー
./Main.cpp: In function 'void _main(int)':
./Main.cpp:163:16: warning: unused parameter 'tc' [-Wunused-parameter]
163 | void _main(int tc) {
| ~~~~^~
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
700 / 700 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_00.txt |
| All |
00_sample_00.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 02_small_00.txt, 02_small_01.txt, 02_small_02.txt, 03_random_00.txt, 03_random_01.txt, 03_random_02.txt, 03_random_03.txt, 03_random_04.txt, 03_random_05.txt, 03_random_06.txt, 03_random_07.txt, 03_random_08.txt, 03_random_09.txt, 03_random_10.txt, 03_random_11.txt, 03_random_12.txt, 03_random_13.txt, 03_random_14.txt, 03_random_15.txt, 03_random_16.txt, 03_random_17.txt, 03_random_18.txt, 03_random_19.txt, 03_random_20.txt, 03_random_21.txt, 03_random_22.txt, 03_random_23.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_00.txt |
AC |
10 ms |
15468 KiB |
| 01_handmade_00.txt |
AC |
25 ms |
15272 KiB |
| 01_handmade_01.txt |
AC |
25 ms |
15400 KiB |
| 01_handmade_02.txt |
AC |
10 ms |
15244 KiB |
| 01_handmade_03.txt |
AC |
9 ms |
15408 KiB |
| 01_handmade_04.txt |
AC |
9 ms |
15332 KiB |
| 02_small_00.txt |
AC |
12 ms |
15456 KiB |
| 02_small_01.txt |
AC |
26 ms |
15456 KiB |
| 02_small_02.txt |
AC |
26 ms |
15400 KiB |
| 03_random_00.txt |
AC |
23 ms |
15408 KiB |
| 03_random_01.txt |
AC |
12 ms |
15392 KiB |
| 03_random_02.txt |
AC |
17 ms |
15296 KiB |
| 03_random_03.txt |
AC |
12 ms |
15248 KiB |
| 03_random_04.txt |
AC |
9 ms |
15404 KiB |
| 03_random_05.txt |
AC |
26 ms |
15244 KiB |
| 03_random_06.txt |
AC |
26 ms |
15392 KiB |
| 03_random_07.txt |
AC |
26 ms |
15244 KiB |
| 03_random_08.txt |
AC |
26 ms |
15308 KiB |
| 03_random_09.txt |
AC |
20 ms |
15376 KiB |
| 03_random_10.txt |
AC |
17 ms |
15220 KiB |
| 03_random_11.txt |
AC |
17 ms |
15392 KiB |
| 03_random_12.txt |
AC |
16 ms |
15272 KiB |
| 03_random_13.txt |
AC |
25 ms |
15272 KiB |
| 03_random_14.txt |
AC |
15 ms |
15400 KiB |
| 03_random_15.txt |
AC |
25 ms |
15392 KiB |
| 03_random_16.txt |
AC |
26 ms |
15408 KiB |
| 03_random_17.txt |
AC |
25 ms |
15392 KiB |
| 03_random_18.txt |
AC |
25 ms |
15308 KiB |
| 03_random_19.txt |
AC |
16 ms |
15308 KiB |
| 03_random_20.txt |
AC |
12 ms |
15456 KiB |
| 03_random_21.txt |
AC |
22 ms |
15392 KiB |
| 03_random_22.txt |
AC |
17 ms |
15400 KiB |
| 03_random_23.txt |
AC |
25 ms |
15392 KiB |