Submission #60588770
Source Code Expand
#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define FORD(i, a, b) for (int i=(a); i>(b); i--)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define PPC(x) __builtin_popcountll(x)
#define MSB(x) (63 - __builtin_clzll(x))
#define LSB(x) __builtin_ctz(x)
#define ARG(x, i) (get<i>(x))
#define LAST(x) std::prev(x.end())
#define ithBit(m, i) ((m) >> (i) & 1)
#define pb push_back
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#define VLD(i, j) (0 <= (i) and (i) < n and 0 <= (j) and (j) < m)
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
template <typename T1, typename T2> inline void remin(T1& a, T2 b) { a = min(a, (T1)b); }
template <typename T1, typename T2> inline void remax(T1& a, T2 b) { a = max(a, (T1)b); }
const int maxN = 1 << 18, mod = 998244353;
template <typename T1, typename T2> inline void addMod(T1& a, T2 b) { a = (a + b) % mod; }
template <typename T1, typename T2> inline void multMod(T1& a, T2 b) { a = a * b % mod; }
long long qpow(long long a, long long b)
{
long long ret = 1ll;
for (; b != 0; b /= 2)
{
if (b & 1) multMod(ret, a);
multMod(a, a);
}
return ret;
}
template <typename T1, typename T2> inline void subMod(T1& a, T2 b) { a = (a - b%mod + mod) % mod; }
template <typename T1, typename T2> inline void divMod(T1& a, T2 b) { a = a * qpow(b, mod-2) % mod; }
long long fact[maxN], tcaf[maxN];
long long dp[maxN];
int T[maxN];
void calcDp(int n)
{
dp[1] = 1;
FOR(i, 2, n+1)
{
if (i % 2 == 0)
dp[i] = 0;
else
dp[i] = dp[i-2] * (i-2) % mod;
}
fact[0] = tcaf[0] = 1ll;
FOR(i, 1, maxN)
fact[i] = fact[i-1] * i % mod;
tcaf[maxN-1] = qpow(fact[maxN-1], mod-2);
FORD(i, maxN-1, 0)
tcaf[i-1] = tcaf[i] * i % mod;
}
void solve()
{
int n, start = 0, sum = 0;
scanf ("%d", &n);
long long res = 1;
T[0] = -1;
calcDp(n);
FOR(i, 1, n+1)
{
scanf ("%d", T+i);
if (T[i] == T[i-1])
continue;
int x = (i - start) / 2;
sum += x;
multMod(res, tcaf[x]);
multMod(res, dp[i - start]);
start = i;
}
int x = (n+1 - start) / 2;
sum += x;
multMod(res, tcaf[x]);
multMod(res, dp[n+1 - start]);
multMod(res, fact[sum]);
if (T[1] == 0)
res = 0;
printf("%lld\n", res);
}
int main()
{
int t = 1;
// scanf ("%d", &t);
FOR(tid, 1, t+1)
{
// printf("Case #%d: ", tid);
solve();
}
return 0;
}
Submission Info
| Submission Time |
|
| Task |
A - Reversi 2 |
| User |
bgrm |
| Language |
C++ 20 (gcc 12.2) |
| Score |
400 |
| Code Size |
2558 Byte |
| Status |
AC |
| Exec Time |
15 ms |
| Memory |
10372 KiB |
Compile Error
Main.cpp: In function ‘void solve()’:
Main.cpp:74:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
74 | scanf ("%d", &n);
| ~~~~~~^~~~~~~~~~
Main.cpp:82:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
82 | scanf ("%d", T+i);
| ~~~~~~^~~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
400 / 400 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
example_00.txt, example_01.txt |
| All |
example_00.txt, example_01.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt |
| Case Name |
Status |
Exec Time |
Memory |
| example_00.txt |
AC |
4 ms |
8028 KiB |
| example_01.txt |
AC |
5 ms |
7928 KiB |
| test_00.txt |
AC |
14 ms |
9980 KiB |
| test_01.txt |
AC |
5 ms |
8076 KiB |
| test_02.txt |
AC |
14 ms |
10108 KiB |
| test_03.txt |
AC |
14 ms |
9824 KiB |
| test_04.txt |
AC |
12 ms |
9612 KiB |
| test_05.txt |
AC |
14 ms |
9996 KiB |
| test_06.txt |
AC |
10 ms |
9016 KiB |
| test_07.txt |
AC |
9 ms |
8784 KiB |
| test_08.txt |
AC |
12 ms |
9524 KiB |
| test_09.txt |
AC |
10 ms |
8988 KiB |
| test_10.txt |
AC |
13 ms |
9904 KiB |
| test_11.txt |
AC |
15 ms |
10156 KiB |
| test_12.txt |
AC |
10 ms |
9136 KiB |
| test_13.txt |
AC |
14 ms |
10012 KiB |
| test_14.txt |
AC |
13 ms |
9656 KiB |
| test_15.txt |
AC |
13 ms |
9692 KiB |
| test_16.txt |
AC |
6 ms |
8216 KiB |
| test_17.txt |
AC |
5 ms |
7912 KiB |
| test_18.txt |
AC |
7 ms |
8608 KiB |
| test_19.txt |
AC |
7 ms |
8464 KiB |
| test_20.txt |
AC |
15 ms |
10140 KiB |
| test_21.txt |
AC |
15 ms |
10292 KiB |
| test_22.txt |
AC |
15 ms |
10132 KiB |
| test_23.txt |
AC |
15 ms |
10128 KiB |
| test_24.txt |
AC |
15 ms |
10372 KiB |
| test_25.txt |
AC |
15 ms |
10128 KiB |
| test_26.txt |
AC |
14 ms |
10296 KiB |
| test_27.txt |
AC |
14 ms |
10124 KiB |
| test_28.txt |
AC |
14 ms |
10108 KiB |
| test_29.txt |
AC |
14 ms |
10292 KiB |
| test_30.txt |
AC |
14 ms |
10132 KiB |
| test_31.txt |
AC |
15 ms |
10248 KiB |
| test_32.txt |
AC |
14 ms |
10296 KiB |
| test_33.txt |
AC |
14 ms |
10192 KiB |
| test_34.txt |
AC |
14 ms |
10104 KiB |
| test_35.txt |
AC |
14 ms |
10124 KiB |
| test_36.txt |
AC |
14 ms |
10108 KiB |
| test_37.txt |
AC |
14 ms |
10136 KiB |
| test_38.txt |
AC |
14 ms |
10124 KiB |
| test_39.txt |
AC |
14 ms |
10232 KiB |