QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#302902 | #7976. 最后的晚餐 | hos_lyric# | 100 ✓ | 351ms | 132016kb | C++14 | 13.6kb | 2024-01-11 15:04:43 | 2024-07-04 03:17:55 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
static constexpr unsigned M = M_;
unsigned x;
constexpr ModInt() : x(0U) {}
constexpr ModInt(unsigned x_) : x(x_ % M) {}
constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
ModInt pow(long long e) const {
if (e < 0) return inv().pow(-e);
ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModInt inv() const {
unsigned a = M, b = x; int y = 0, z = 1;
for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
assert(a == 1U); return ModInt(y);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModInt &a) const { return (x == a.x); }
bool operator!=(const ModInt &a) const { return (x != a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
constexpr unsigned MO = 998244353U;
constexpr unsigned MO2 = 2U * MO;
constexpr int FFT_MAX = 23;
using Mint = ModInt<MO>;
constexpr Mint FFT_ROOTS[FFT_MAX + 1] = {1U, 998244352U, 911660635U, 372528824U, 929031873U, 452798380U, 922799308U, 781712469U, 476477967U, 166035806U, 258648936U, 584193783U, 63912897U, 350007156U, 666702199U, 968855178U, 629671588U, 24514907U, 996173970U, 363395222U, 565042129U, 733596141U, 267099868U, 15311432U};
constexpr Mint INV_FFT_ROOTS[FFT_MAX + 1] = {1U, 998244352U, 86583718U, 509520358U, 337190230U, 87557064U, 609441965U, 135236158U, 304459705U, 685443576U, 381598368U, 335559352U, 129292727U, 358024708U, 814576206U, 708402881U, 283043518U, 3707709U, 121392023U, 704923114U, 950391366U, 428961804U, 382752275U, 469870224U};
constexpr Mint FFT_RATIOS[FFT_MAX] = {911660635U, 509520358U, 369330050U, 332049552U, 983190778U, 123842337U, 238493703U, 975955924U, 603855026U, 856644456U, 131300601U, 842657263U, 730768835U, 942482514U, 806263778U, 151565301U, 510815449U, 503497456U, 743006876U, 741047443U, 56250497U, 867605899U};
constexpr Mint INV_FFT_RATIOS[FFT_MAX] = {86583718U, 372528824U, 373294451U, 645684063U, 112220581U, 692852209U, 155456985U, 797128860U, 90816748U, 860285882U, 927414960U, 354738543U, 109331171U, 293255632U, 535113200U, 308540755U, 121186627U, 608385704U, 438932459U, 359477183U, 824071951U, 103369235U};
// as[rev(i)] <- \sum_j \zeta^(ij) as[j]
void fft(Mint *as, int n) {
assert(!(n & (n - 1))); assert(1 <= n); assert(n <= 1 << FFT_MAX);
int m = n;
if (m >>= 1) {
for (int i = 0; i < m; ++i) {
const unsigned x = as[i + m].x; // < MO
as[i + m].x = as[i].x + MO - x; // < 2 MO
as[i].x += x; // < 2 MO
}
}
if (m >>= 1) {
Mint prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + m; ++i) {
const unsigned x = (prod * as[i + m]).x; // < MO
as[i + m].x = as[i].x + MO - x; // < 3 MO
as[i].x += x; // < 3 MO
}
prod *= FFT_RATIOS[__builtin_ctz(++h)];
}
}
for (; m; ) {
if (m >>= 1) {
Mint prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + m; ++i) {
const unsigned x = (prod * as[i + m]).x; // < MO
as[i + m].x = as[i].x + MO - x; // < 4 MO
as[i].x += x; // < 4 MO
}
prod *= FFT_RATIOS[__builtin_ctz(++h)];
}
}
if (m >>= 1) {
Mint prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + m; ++i) {
const unsigned x = (prod * as[i + m]).x; // < MO
as[i].x = (as[i].x >= MO2) ? (as[i].x - MO2) : as[i].x; // < 2 MO
as[i + m].x = as[i].x + MO - x; // < 3 MO
as[i].x += x; // < 3 MO
}
prod *= FFT_RATIOS[__builtin_ctz(++h)];
}
}
}
for (int i = 0; i < n; ++i) {
as[i].x = (as[i].x >= MO2) ? (as[i].x - MO2) : as[i].x; // < 2 MO
as[i].x = (as[i].x >= MO) ? (as[i].x - MO) : as[i].x; // < MO
}
}
// as[i] <- (1/n) \sum_j \zeta^(-ij) as[rev(j)]
void invFft(Mint *as, int n) {
assert(!(n & (n - 1))); assert(1 <= n); assert(n <= 1 << FFT_MAX);
int m = 1;
if (m < n >> 1) {
Mint prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + m; ++i) {
const unsigned long long y = as[i].x + MO - as[i + m].x; // < 2 MO
as[i].x += as[i + m].x; // < 2 MO
as[i + m].x = (prod.x * y) % MO; // < MO
}
prod *= INV_FFT_RATIOS[__builtin_ctz(++h)];
}
m <<= 1;
}
for (; m < n >> 1; m <<= 1) {
Mint prod = 1U;
for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
for (int i = i0; i < i0 + (m >> 1); ++i) {
const unsigned long long y = as[i].x + MO2 - as[i + m].x; // < 4 MO
as[i].x += as[i + m].x; // < 4 MO
as[i].x = (as[i].x >= MO2) ? (as[i].x - MO2) : as[i].x; // < 2 MO
as[i + m].x = (prod.x * y) % MO; // < MO
}
for (int i = i0 + (m >> 1); i < i0 + m; ++i) {
const unsigned long long y = as[i].x + MO - as[i + m].x; // < 2 MO
as[i].x += as[i + m].x; // < 2 MO
as[i + m].x = (prod.x * y) % MO; // < MO
}
prod *= INV_FFT_RATIOS[__builtin_ctz(++h)];
}
}
if (m < n) {
for (int i = 0; i < m; ++i) {
const unsigned y = as[i].x + MO2 - as[i + m].x; // < 4 MO
as[i].x += as[i + m].x; // < 4 MO
as[i + m].x = y; // < 4 MO
}
}
const Mint invN = Mint(n).inv();
for (int i = 0; i < n; ++i) {
as[i] *= invN;
}
}
void fft(vector<Mint> &as) {
fft(as.data(), as.size());
}
void invFft(vector<Mint> &as) {
invFft(as.data(), as.size());
}
vector<Mint> convolve(vector<Mint> as, vector<Mint> bs) {
if (as.empty() || bs.empty()) return {};
const int len = as.size() + bs.size() - 1;
int n = 1;
for (; n < len; n <<= 1) {}
as.resize(n); fft(as);
bs.resize(n); fft(bs);
for (int i = 0; i < n; ++i) as[i] *= bs[i];
invFft(as);
as.resize(len);
return as;
}
vector<Mint> square(vector<Mint> as) {
if (as.empty()) return {};
const int len = as.size() + as.size() - 1;
int n = 1;
for (; n < len; n <<= 1) {}
as.resize(n); fft(as);
for (int i = 0; i < n; ++i) as[i] *= as[i];
invFft(as);
as.resize(len);
return as;
}
////////////////////////////////////////////////////////////////////////////////
int N;
vector<int> A;
int F[13];
vector<Mint> dp;
// *= (1 + X^d + ... + X^(fd))
void update(int f, int d) {
int len = dp.size();
if (d) {
len += f * d;
dp.resize(len, 0);
for (int x = len; --x >= (f + 1) * d; ) dp[x] -= dp[x - (f + 1) * d];
for (int x = d; x < len; ++x) dp[x] += dp[x - d];
} else {
for (int x = 0; x < len; ++x) dp[x] *= (f + 1);
}
}
// \sum (floor(sum/10) + 1)
Mint easy() {
dp = {1};
for (int a = 1; a <= 12; ++a) {
update(F[a], a);
}
Mint ret = 0;
for (int x = 0; x < (int)dp.size(); ++x) {
ret += dp[x] * (x / 10 + 1);
}
return ret;
}
namespace slow {
int LEN;
int LENS[2010];
Mint DP[2010][16010];
// *= (1 + W X^d + ... + W^f X^(fd))
void UPDATE(int f, int d) {
LEN += f;
for (int w = 1; w < LEN; ++w) chmax(LENS[w], LENS[w - 1] + d);
for (int w = LEN; --w >= f + 1; ) for (int x = (f + 1) * d; x < LENS[w]; ++x) DP[w][x] -= DP[w - (f + 1)][x - (f + 1) * d];
for (int w = 1; w < LEN; ++w) for (int x = d; x < LENS[w]; ++x) DP[w][x] += DP[w - 1][x - d];
}
Mint run() {
dp = {1};
for (int a = 2; a <= 10; ++a) if (a % 2 == 0) update(F[a], 10 - a);
LEN = 1;
memset(LENS, 0, sizeof(LENS));
memset(DP, 0, sizeof(DP));
LENS[0] = dp.size();
copy(dp.begin(), dp.end(), DP[0]);
for (int a = 2; a <= 10; ++a) if (a % 2 != 0) UPDATE(F[a], 10 - a);
vector<Mint> ways(10 * N + 1, 0);
for (int w = 0; w < LEN; ++w) for (int x = 0; x < LENS[w]; ++x) if (DP[w][x]) {
for (int f1 = 0; f1 <= F[1]; ++f1) for (int f11 = 0; f11 <= F[11]; ++f11) {
int heal = x;
const int g1 = min(f1, w + f11);
heal += g1 * (+9);
heal += ((f1 - g1 + 1) / 2) * (-1);
heal += ((f1 - g1) / 2) * (+9);
ways[N + (heal - f11)] += DP[w][x];
}
}
cerr<<"ways = "<<ways<<endl;
Mint ans = 0;
for (int i = 0; i < (int)ways.size(); ++i) if (ways[i]) {
for (int f12 = 0; f12 <= F[12]; ++f12) {
const int skip = max(f12 * 2 - (i - N), 0) / 10;
ans += ways[i] * skip;
}
}
cerr<<"ans = "<<ans<<endl;
const Mint eas = easy();
ans = eas - ans;
return ans;
}
} // slow
namespace fast {
int LEN;
int LENS[2010];
Mint DP[2010][16010];
// *= (1 + W X^d + ... + W^f X^(fd))
void UPDATE(int f, int d) {
LEN += f;
for (int w = 1; w < LEN; ++w) chmax(LENS[w], LENS[w - 1] + d);
for (int w = LEN; --w >= f + 1; ) for (int x = (f + 1) * d; x < LENS[w]; ++x) DP[w][x] -= DP[w - (f + 1)][x - (f + 1) * d];
for (int w = 1; w < LEN; ++w) for (int x = d; x < LENS[w]; ++x) DP[w][x] += DP[w - 1][x - d];
}
Mint run() {
dp = {1};
for (int a = 2; a <= 10; ++a) if (a % 2 == 0) update(F[a], 10 - a);
LEN = 1;
memset(LENS, 0, sizeof(LENS));
memset(DP, 0, sizeof(DP));
LENS[0] = dp.size();
copy(dp.begin(), dp.end(), DP[0]);
for (int a = 2; a <= 10; ++a) if (a % 2 != 0) UPDATE(F[a], 10 - a);
vector<Mint> ways(10 * N + 1, 0);
for (int w = 0; w < LEN; ++w) {
vector<int> coef(10 * N + 1, 0);
for (int f1 = 0; f1 <= F[1]; ++f1) for (int f11 = 0; f11 <= F[11]; ++f11) {
int heal = 0;
const int g1 = min(f1, w + f11);
heal += g1 * (+9);
heal += ((f1 - g1 + 1) / 2) * (-1);
heal += ((f1 - g1) / 2) * (+9);
++coef[N + (heal - f11)];
}
int lb = coef.size(), ub = -1;
for (int i = 0; i < (int)coef.size(); ++i) if (coef[i]) {
chmin(lb, i);
chmax(ub, i);
}
if (lb <= ub) {
const auto prod = convolve(
vector<Mint>(coef.begin() + lb, coef.begin() + (ub + 1)),
vector<Mint>(DP[w], DP[w] + LENS[w])
);
for (int i = 0; i < (int)prod.size(); ++i) {
ways[lb + i] += prod[i];
}
}
}
cerr<<"ways = "<<ways<<endl;
Mint ans = 0;
for (int i = 0; i < (int)ways.size(); ++i) if (ways[i]) {
for (int f12 = 0; f12 <= F[12]; ++f12) {
const int skip = max(f12 * 2 - (i - N), 0) / 10;
ans += ways[i] * skip;
}
}
cerr<<"ans = "<<ans<<endl;
const Mint eas = easy();
ans = eas - ans;
return ans;
}
} // fast
int main() {
for (; ~scanf("%d", &N); ) {
A.resize(N);
for (int i = 0; i < N; ++i) {
scanf("%d", &A[i]);
}
memset(F, 0, sizeof(F));
for (int i = 0; i < N; ++i) {
++F[A[i]];
}
cerr<<"F = ";pv(F,F+13);
const Mint ans = fast::run();
printf("%u\n", ans.x);
#ifndef LOCAL
break;
#endif
}
return 0;
}
详细
Subtask #1:
score: 4
Accepted
Test #1:
score: 4
Accepted
time: 8ms
memory: 131172kb
input:
5 1 1 4 5 1 4
output:
19
result:
ok single line: '19'
Test #2:
score: 0
Accepted
time: 0ms
memory: 130688kb
input:
20 6 1 8 6 10 8 4 3 9 3 6 8 5 11 6 8 3 12 1 12
output:
203040
result:
ok single line: '203040'
Test #3:
score: 0
Accepted
time: 3ms
memory: 131352kb
input:
20 7 6 3 5 12 2 1 10 3 8 5 8 1 9 11 7 4 6 2 4
output:
656102
result:
ok single line: '656102'
Test #4:
score: 0
Accepted
time: 4ms
memory: 131136kb
input:
20 1 11 11 7 11 11 5 3 4 8 10 5 12 7 12 1 11 11 1 12
output:
133044
result:
ok single line: '133044'
Subtask #2:
score: 12
Accepted
Test #5:
score: 12
Accepted
time: 4ms
memory: 130628kb
input:
25 7 12 12 4 7 2 2 4 5 3 10 1 2 10 12 7 4 9 8 12 3 5 4 7 5
output:
1209600
result:
ok single line: '1209600'
Test #6:
score: 0
Accepted
time: 4ms
memory: 130760kb
input:
30 2 8 12 3 4 5 9 1 11 1 12 6 3 4 5 8 10 1 9 10 5 10 10 9 2 12 5 4 1 12
output:
11070000
result:
ok single line: '11070000'
Test #7:
score: 0
Accepted
time: 12ms
memory: 130972kb
input:
30 9 2 11 8 3 7 4 11 12 7 3 2 1 4 9 4 5 1 5 12 2 6 6 3 8 5 6 10 10 1
output:
28068252
result:
ok single line: '28068252'
Test #8:
score: 0
Accepted
time: 7ms
memory: 130004kb
input:
30 10 5 1 1 8 12 5 10 1 1 5 10 1 11 11 5 11 12 12 8 1 1 10 12 4 1 11 4 12 9
output:
1312095
result:
ok single line: '1312095'
Test #9:
score: 0
Accepted
time: 6ms
memory: 129972kb
input:
27 9 6 5 5 10 1 10 9 7 10 3 6 1 11 11 9 9 4 9 1 9 1 4 9 4 9 6
output:
979772
result:
ok single line: '979772'
Test #10:
score: 0
Accepted
time: 0ms
memory: 129692kb
input:
40 8 9 2 4 8 2 9 8 4 10 1 9 4 4 9 6 7 11 7 2 1 7 10 6 2 10 5 11 3 4 5 10 1 6 6 4 9 7 3 7
output:
171460800
result:
ok single line: '171460800'
Test #11:
score: 0
Accepted
time: 0ms
memory: 131540kb
input:
40 1 5 2 2 12 12 6 4 8 8 9 11 3 4 3 8 4 3 6 3 10 5 12 1 1 5 1 9 10 7 7 2 2 10 7 11 6 11 9 4
output:
522240000
result:
ok single line: '522240000'
Test #12:
score: 0
Accepted
time: 0ms
memory: 130624kb
input:
40 1 12 1 11 1 5 1 1 1 12 12 1 9 4 1 11 6 12 5 9 11 4 1 12 1 12 12 4 9 9 11 11 12 11 11 7 9 11 11 10
output:
8721848
result:
ok single line: '8721848'
Subtask #3:
score: 16
Accepted
Test #13:
score: 16
Accepted
time: 0ms
memory: 131200kb
input:
162 7 9 1 8 5 10 11 4 5 11 4 5 5 5 1 6 9 9 5 5 7 11 8 5 11 2 4 8 5 2 5 2 7 5 10 6 6 4 8 2 5 11 2 11 11 11 7 6 3 2 10 7 4 4 1 9 4 10 11 4 4 4 5 11 4 10 11 2 11 9 9 9 2 3 3 9 6 1 11 2 10 6 2 4 9 1 6 7 11 2 8 3 4 10 7 8 1 7 1 4 10 6 6 6 2 6 2 2 11 9 1 11 3 5 1 8 10 1 1 7 2 8 2 11 3 2 9 4 9 5 11 11 4 8 ...
output:
7029577
result:
ok single line: '7029577'
Test #14:
score: 0
Accepted
time: 351ms
memory: 129960kb
input:
2000 5 7 5 9 2 3 1 11 10 2 9 2 8 8 4 7 10 4 10 6 7 6 8 7 3 4 3 10 6 1 7 11 3 7 8 5 8 9 10 5 3 1 3 10 6 3 2 5 4 10 2 8 11 3 6 7 1 11 4 5 9 6 2 2 5 5 6 8 9 8 7 8 7 2 2 2 9 10 4 10 1 4 7 5 2 3 7 6 1 8 7 11 11 7 11 10 4 1 5 3 11 11 4 8 1 6 5 7 5 5 10 7 11 10 5 2 9 1 6 5 3 9 1 11 4 4 5 7 1 11 6 4 3 9 4 1...
output:
371307514
result:
ok single line: '371307514'
Test #15:
score: 0
Accepted
time: 242ms
memory: 130580kb
input:
2000 11 11 9 11 9 1 1 11 5 6 11 11 11 4 2 3 8 1 9 8 9 4 11 7 4 11 3 11 11 11 11 11 4 11 11 9 11 9 10 7 2 6 11 5 5 4 11 4 7 9 7 11 11 7 1 3 5 10 11 11 11 2 1 1 11 11 2 2 6 11 2 7 11 11 6 9 11 5 10 2 11 5 2 11 7 11 11 6 11 7 11 5 9 11 1 11 9 4 7 11 5 11 11 1 2 8 11 3 3 11 1 11 11 9 5 11 3 7 11 11 11 6...
output:
513895468
result:
ok single line: '513895468'
Test #16:
score: 0
Accepted
time: 46ms
memory: 130020kb
input:
2000 4 11 10 11 1 11 11 11 11 11 11 5 11 5 11 11 11 11 10 5 11 3 11 11 5 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 4 11 7 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 1 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 9 11 11 11 11 11 11 11 11 11 1 11 6 11 11 11 11 11 11 3 11 ...
output:
359825045
result:
ok single line: '359825045'
Subtask #4:
score: 12
Accepted
Test #17:
score: 12
Accepted
time: 8ms
memory: 131204kb
input:
306 4 6 11 3 8 8 4 2 8 10 6 8 12 8 8 9 10 9 5 10 11 7 10 11 8 2 10 5 4 2 8 5 3 8 12 11 11 2 11 7 10 9 7 6 4 11 11 2 11 6 12 8 6 6 12 7 11 10 3 5 2 3 7 8 2 10 9 5 11 7 7 8 3 4 9 9 2 7 2 12 8 2 7 10 8 7 6 12 7 3 3 3 2 6 2 4 10 11 8 8 7 3 6 11 9 4 9 3 12 10 12 6 8 11 6 2 8 10 10 6 5 11 11 7 5 5 10 12 5...
output:
537422792
result:
ok single line: '537422792'
Test #18:
score: 0
Accepted
time: 251ms
memory: 130476kb
input:
2000 2 9 12 6 11 4 9 7 12 5 4 4 10 9 3 12 8 2 4 8 4 11 10 8 11 11 5 9 8 9 6 12 9 12 9 7 3 2 8 8 2 3 8 9 3 3 6 9 6 4 8 11 4 9 9 9 10 5 12 8 9 4 10 10 9 9 6 4 8 11 11 3 9 3 7 3 10 8 11 12 8 4 9 8 11 7 12 5 9 10 5 4 11 5 11 3 11 12 7 11 9 4 3 2 2 4 3 6 3 10 11 3 5 6 7 9 6 10 7 6 3 12 12 8 3 8 5 7 12 10...
output:
839026549
result:
ok single line: '839026549'
Test #19:
score: 0
Accepted
time: 11ms
memory: 130624kb
input:
2000 12 11 12 12 12 12 11 11 4 11 12 5 11 11 12 11 11 12 6 12 11 11 12 12 11 12 12 12 11 11 7 5 11 11 11 10 5 12 12 12 11 11 12 12 11 11 11 11 12 11 12 11 12 12 6 12 12 11 11 12 12 11 11 12 11 12 11 12 12 11 11 12 12 12 12 12 7 11 11 12 11 12 4 11 12 12 11 11 12 11 11 11 11 11 12 11 11 11 11 11 12 1...
output:
58568833
result:
ok single line: '58568833'
Test #20:
score: 0
Accepted
time: 70ms
memory: 130796kb
input:
2000 12 11 11 11 11 6 12 6 2 5 12 11 11 7 11 11 11 11 4 12 11 12 11 8 12 6 3 2 11 12 12 12 9 8 12 12 12 7 9 12 6 9 11 11 12 2 11 11 4 12 2 11 11 12 11 11 2 11 12 12 11 11 12 2 7 12 5 6 5 11 2 11 4 7 11 11 11 12 11 11 12 6 9 12 5 11 12 4 12 7 11 12 8 4 12 4 12 9 12 11 12 7 11 7 3 12 7 12 7 12 11 11 1...
output:
815809248
result:
ok single line: '815809248'
Test #21:
score: 0
Accepted
time: 15ms
memory: 130892kb
input:
2000 12 11 12 12 12 12 11 12 12 12 12 12 11 5 11 11 12 12 12 12 12 12 12 12 12 12 12 12 12 12 11 11 11 12 12 5 5 12 12 12 11 12 11 12 12 12 12 12 12 12 12 12 12 11 12 11 12 12 12 12 12 12 12 11 8 12 12 12 12 12 10 12 11 12 12 11 12 12 11 11 12 11 12 12 12 3 7 11 12 12 12 12 12 12 11 12 12 11 12 12 1...
output:
444619177
result:
ok single line: '444619177'
Subtask #5:
score: 12
Accepted
Test #22:
score: 12
Accepted
time: 4ms
memory: 129612kb
input:
68 2 11 8 12 7 11 11 7 6 5 10 3 5 12 4 5 1 6 5 11 6 9 1 1 11 5 12 3 12 9 11 1 1 12 9 4 11 4 6 10 4 1 10 6 2 7 3 2 11 5 4 5 2 6 4 11 3 2 10 8 1 9 4 8 2 3 9 9
output:
970946217
result:
ok single line: '970946217'
Test #23:
score: 0
Accepted
time: 4ms
memory: 130016kb
input:
100 2 5 1 6 10 1 12 7 9 11 4 8 1 6 10 10 4 4 4 6 4 8 5 10 5 1 8 10 6 11 7 9 5 12 5 9 2 10 9 12 10 1 6 9 5 7 1 11 2 8 4 11 12 9 3 6 12 1 2 4 7 12 3 7 11 3 1 2 7 7 4 2 6 2 5 6 8 11 10 2 10 7 5 3 3 9 2 12 9 7 9 9 12 7 8 7 11 6 8 2
output:
242285391
result:
ok single line: '242285391'
Test #24:
score: 0
Accepted
time: 3ms
memory: 130656kb
input:
100 1 2 11 11 11 12 2 5 5 7 2 7 1 10 5 1 8 6 2 1 8 1 3 10 9 6 4 4 2 4 3 3 1 5 10 3 7 5 12 3 12 11 5 8 10 4 4 10 1 11 6 7 2 8 7 8 4 3 4 6 10 10 8 1 9 6 3 12 7 12 1 3 9 5 6 8 5 7 2 9 2 2 10 6 12 3 4 9 9 9 12 12 7 11 8 11 9 11 6 4
output:
981520513
result:
ok single line: '981520513'
Test #25:
score: 0
Accepted
time: 0ms
memory: 130964kb
input:
100 1 11 3 11 2 12 7 5 4 6 12 9 12 7 1 1 12 5 12 1 9 1 12 1 12 7 12 12 6 8 8 11 1 2 10 1 12 9 1 12 1 11 3 1 1 11 12 6 11 8 11 12 11 9 10 2 1 1 2 1 11 1 9 12 3 1 12 1 11 9 11 6 2 1 11 12 11 5 11 1 11 10 7 4 8 12 12 12 11 2 6 1 12 12 1 11 1 11 4 11
output:
553152067
result:
ok single line: '553152067'
Test #26:
score: 0
Accepted
time: 7ms
memory: 129960kb
input:
100 12 12 12 11 12 12 1 12 8 9 12 1 11 12 12 11 12 9 11 11 11 11 6 12 11 12 1 11 11 12 1 11 11 12 12 11 11 12 11 12 12 12 11 1 1 12 11 1 12 12 12 11 12 6 1 10 12 11 12 11 12 12 11 11 11 11 10 12 12 11 11 11 1 11 12 1 11 12 11 11 11 11 1 1 11 10 11 11 12 12 11 11 12 11 1 11 1 12 12 12
output:
83201920
result:
ok single line: '83201920'
Subtask #6:
score: 8
Accepted
Test #27:
score: 8
Accepted
time: 8ms
memory: 130928kb
input:
103 3 4 3 6 5 12 4 4 5 5 11 2 5 3 11 10 4 2 8 6 2 8 4 5 1 1 4 8 11 11 7 1 3 11 3 1 1 7 4 4 3 3 9 7 9 7 1 3 12 1 2 12 3 1 9 11 5 12 5 11 6 7 7 12 7 8 7 4 10 10 8 4 4 8 6 10 7 3 7 8 7 1 12 1 12 1 8 4 9 10 6 12 8 12 5 10 3 10 4 6 11 10 7
output:
160323719
result:
ok single line: '160323719'
Test #28:
score: 0
Accepted
time: 11ms
memory: 131376kb
input:
300 7 10 7 12 7 1 6 9 10 5 10 3 10 5 6 8 2 4 7 1 10 8 3 2 11 11 12 2 5 4 10 2 12 10 3 2 5 11 4 6 6 3 4 3 2 7 12 9 3 5 3 5 3 11 12 4 4 9 3 7 10 6 5 4 7 6 6 9 4 6 7 10 7 9 11 2 12 2 9 5 6 1 12 9 2 10 10 8 1 7 8 6 9 12 5 7 9 8 6 7 7 11 8 3 6 5 1 10 10 1 6 3 3 12 11 1 6 11 9 9 10 2 6 3 8 10 11 10 2 11 1...
output:
349661228
result:
ok single line: '349661228'
Test #29:
score: 0
Accepted
time: 0ms
memory: 130828kb
input:
300 11 12 11 12 11 12 11 12 12 12 11 12 11 12 11 12 8 12 12 12 12 11 12 12 4 11 12 2 11 12 11 11 12 12 12 12 11 11 11 4 12 11 12 12 12 12 11 11 11 11 5 11 12 12 12 11 12 12 11 11 12 12 3 11 12 12 12 12 12 12 12 5 12 12 12 12 12 11 11 12 12 11 4 11 12 11 12 11 11 6 12 11 11 12 11 12 11 12 12 11 8 12 ...
output:
103860914
result:
ok single line: '103860914'
Test #30:
score: 0
Accepted
time: 7ms
memory: 130360kb
input:
300 11 2 11 11 12 4 3 2 12 1 4 3 11 12 12 10 1 12 12 11 11 12 4 8 1 7 11 12 1 11 12 9 12 1 4 4 11 10 12 12 11 4 12 11 1 8 2 1 12 2 3 11 6 12 12 11 4 12 5 1 6 1 11 1 11 11 12 1 3 12 12 1 12 3 11 11 1 12 9 12 12 12 12 1 11 1 1 11 10 11 5 12 12 2 11 12 12 1 1 11 11 1 3 11 11 12 12 3 11 12 12 3 3 12 2 1...
output:
404838112
result:
ok single line: '404838112'
Test #31:
score: 0
Accepted
time: 4ms
memory: 131492kb
input:
300 12 1 12 11 12 1 1 11 11 12 11 11 11 11 11 12 1 1 12 11 1 11 12 11 1 12 12 8 12 11 11 11 11 11 12 2 12 12 12 7 11 11 11 11 12 12 12 12 11 12 12 12 12 12 11 11 11 12 11 12 9 12 12 11 1 1 1 12 11 11 12 2 11 11 11 11 12 1 1 12 11 1 11 12 11 12 1 11 12 11 12 11 12 1 1 12 12 12 12 11 12 11 1 1 11 8 12...
output:
325727434
result:
ok single line: '325727434'
Test #32:
score: 0
Accepted
time: 3ms
memory: 130776kb
input:
300 1 1 1 11 1 1 11 1 11 11 11 11 11 11 2 1 4 11 11 11 1 11 11 11 1 11 11 1 11 11 11 11 1 11 11 11 12 1 11 11 11 11 1 1 11 1 1 1 11 11 1 1 2 11 11 1 11 11 1 1 11 1 1 1 7 1 1 11 1 1 1 11 1 11 1 11 3 1 1 1 1 2 1 1 11 11 11 11 1 11 1 11 1 11 11 11 11 11 1 11 11 11 11 1 11 1 11 11 1 5 1 11 11 1 11 1 1 1...
output:
105323732
result:
ok single line: '105323732'
Test #33:
score: 0
Accepted
time: 0ms
memory: 130480kb
input:
300 12 1 5 11 1 7 1 1 1 12 11 1 11 1 12 1 11 11 12 1 1 12 1 12 11 12 1 1 1 1 6 12 12 5 1 11 12 11 1 10 12 1 12 1 12 8 1 1 1 1 1 12 12 12 12 11 1 11 12 2 1 1 1 11 11 11 11 1 1 10 1 11 1 11 1 1 1 1 11 11 11 1 11 12 7 12 9 11 11 1 1 11 11 11 1 1 1 1 4 1 11 1 11 11 10 12 3 1 10 1 11 12 1 11 12 11 4 12 1...
output:
277518558
result:
ok single line: '277518558'
Subtask #7:
score: 12
Accepted
Test #34:
score: 12
Accepted
time: 7ms
memory: 130224kb
input:
126 12 12 10 9 1 4 7 10 8 6 9 7 3 4 6 4 1 6 2 9 5 5 1 7 3 8 1 10 3 10 7 3 2 6 2 12 6 11 1 7 12 4 7 1 2 10 1 5 11 10 4 4 7 5 5 6 9 8 5 11 6 12 10 10 10 6 8 11 7 3 1 1 10 8 6 4 9 3 3 7 1 8 12 6 12 12 6 10 10 7 9 1 1 3 1 2 1 5 8 4 9 2 7 6 7 2 7 11 7 3 3 6 11 7 4 2 3 10 5 3 7 10 11 9 11 2
output:
81214287
result:
ok single line: '81214287'
Test #35:
score: 0
Accepted
time: 23ms
memory: 131596kb
input:
600 1 2 9 8 9 11 9 7 3 12 7 12 6 8 12 4 5 12 6 12 1 12 4 6 11 4 3 4 10 6 6 5 11 1 7 5 1 6 1 3 5 6 10 5 11 12 9 10 7 10 12 5 8 7 2 8 9 5 6 9 6 9 7 9 7 8 4 1 9 5 7 7 6 2 3 7 8 1 5 4 2 9 12 5 6 10 12 3 11 1 8 12 2 6 2 5 5 8 12 5 2 2 11 3 12 5 1 1 1 10 1 6 4 1 5 10 1 6 5 11 11 11 12 8 6 3 4 7 4 1 8 4 9 ...
output:
200354829
result:
ok single line: '200354829'
Test #36:
score: 0
Accepted
time: 4ms
memory: 130852kb
input:
600 11 11 11 11 12 11 11 7 11 6 7 11 11 12 11 11 12 8 12 11 12 11 7 11 11 11 12 12 12 11 12 12 12 12 12 11 12 12 12 12 11 12 12 12 12 11 11 11 12 12 11 11 12 12 12 11 11 11 11 12 12 12 12 11 11 12 11 12 12 12 11 12 12 12 11 11 3 12 11 11 11 11 8 12 11 12 12 12 11 12 12 12 12 11 12 11 11 12 11 12 11 ...
output:
336892409
result:
ok single line: '336892409'
Test #37:
score: 0
Accepted
time: 19ms
memory: 131512kb
input:
600 1 12 1 10 11 12 12 5 12 12 11 12 1 12 5 6 12 12 5 1 7 8 6 12 11 11 11 8 1 5 1 11 7 11 12 4 1 11 1 12 12 5 11 12 1 12 11 12 10 1 2 1 12 12 11 1 10 11 6 7 1 1 8 12 12 1 12 1 11 11 12 11 10 11 1 11 11 10 11 12 1 6 11 6 1 1 6 9 11 3 12 6 4 10 1 11 12 11 12 1 1 6 12 11 11 1 2 9 2 11 8 4 12 2 1 3 11 1...
output:
814315308
result:
ok single line: '814315308'
Test #38:
score: 0
Accepted
time: 7ms
memory: 131584kb
input:
600 11 12 12 12 11 12 1 12 11 11 11 11 12 12 4 1 1 12 4 12 1 1 11 11 3 11 12 1 11 11 12 4 12 12 12 11 11 11 7 11 12 12 1 10 12 11 11 1 1 11 12 11 11 12 11 11 11 11 1 12 12 1 12 4 11 12 12 12 11 11 12 11 1 11 11 12 12 11 1 11 12 3 11 1 11 1 1 11 1 1 12 11 12 1 12 12 12 11 12 1 11 12 12 11 12 5 12 12 ...
output:
459077640
result:
ok single line: '459077640'
Test #39:
score: 0
Accepted
time: 7ms
memory: 130172kb
input:
600 11 11 1 11 11 11 11 5 1 11 1 1 1 1 11 1 11 11 11 1 11 11 1 1 11 1 1 1 11 1 11 11 1 1 11 11 11 1 1 1 1 6 1 11 11 11 6 11 1 1 1 8 1 1 1 1 1 4 11 1 1 11 7 1 1 11 1 11 11 1 1 11 4 11 11 11 11 1 11 1 1 11 11 11 11 11 11 11 1 11 1 11 6 1 1 11 11 1 11 1 10 12 1 11 1 11 7 1 11 1 11 1 11 11 1 11 1 1 11 1...
output:
412416418
result:
ok single line: '412416418'
Test #40:
score: 0
Accepted
time: 3ms
memory: 130056kb
input:
600 11 1 1 11 11 1 1 12 6 1 11 11 1 11 1 12 11 11 11 1 1 11 1 12 12 11 2 1 11 12 12 1 12 12 1 1 1 1 1 1 1 1 1 12 12 1 1 1 12 1 1 12 10 12 11 1 1 12 11 12 11 11 1 11 1 12 1 1 12 1 11 1 1 1 1 1 12 1 1 12 1 11 11 1 12 11 1 12 1 1 12 11 1 1 11 1 11 1 12 1 1 11 1 12 11 1 11 12 1 12 12 2 1 12 11 7 1 12 12...
output:
658876033
result:
ok single line: '658876033'
Test #41:
score: 0
Accepted
time: 0ms
memory: 130848kb
input:
600 1 11 12 11 11 12 11 12 11 11 11 11 12 11 11 12 12 1 11 1 10 11 1 1 12 1 12 12 12 1 11 11 1 1 12 12 11 11 12 12 12 12 12 1 1 12 12 12 12 12 12 11 12 12 12 12 1 11 11 11 12 12 11 12 12 12 11 11 11 11 12 11 12 12 11 11 12 11 9 12 11 12 11 11 11 1 12 12 12 1 11 11 1 11 12 1 1 11 12 12 12 11 1 12 12 ...
output:
1405815
result:
ok single line: '1405815'
Subtask #8:
score: 24
Accepted
Test #42:
score: 24
Accepted
time: 0ms
memory: 130960kb
input:
118 2 2 6 11 2 1 12 12 5 12 6 1 4 2 2 2 10 11 4 5 8 5 6 1 1 8 10 6 6 4 4 8 6 5 4 2 6 2 7 7 6 3 1 10 4 12 10 4 12 9 11 3 4 9 2 1 5 3 12 4 2 2 6 2 4 11 3 9 11 9 1 6 12 1 4 8 9 11 8 9 7 10 11 6 7 11 8 4 5 3 7 8 1 9 4 8 12 10 6 12 4 2 8 6 2 9 11 9 6 4 8 1 7 11 3 6 7 2
output:
348282473
result:
ok single line: '348282473'
Test #43:
score: 0
Accepted
time: 270ms
memory: 130604kb
input:
2000 2 8 8 9 1 6 2 3 6 6 5 7 7 1 4 8 6 9 1 3 5 6 5 3 6 9 12 3 8 6 1 3 4 9 9 1 11 10 2 2 6 2 3 5 7 2 11 8 2 2 1 9 4 7 8 7 8 7 7 7 4 10 4 10 11 3 6 5 3 7 4 2 5 10 5 12 12 10 1 12 8 1 9 9 6 1 8 10 8 11 11 2 12 4 11 5 1 1 12 11 11 5 11 9 3 6 9 12 4 7 4 5 8 4 6 11 3 11 2 2 6 12 11 12 10 4 2 3 6 3 11 12 4...
output:
993518469
result:
ok single line: '993518469'
Test #44:
score: 0
Accepted
time: 11ms
memory: 131372kb
input:
2000 11 11 12 12 11 12 12 11 11 12 12 11 11 12 12 12 12 12 11 12 12 12 12 11 9 11 11 11 4 11 11 11 11 11 11 12 12 12 11 11 12 12 11 11 11 11 11 12 12 11 11 12 12 9 12 11 12 12 12 12 12 11 11 12 12 11 11 12 12 11 12 12 12 11 12 12 12 11 12 11 12 12 11 12 11 12 11 11 12 12 11 11 11 12 5 11 12 9 11 12 ...
output:
502822032
result:
ok single line: '502822032'
Test #45:
score: 0
Accepted
time: 206ms
memory: 130584kb
input:
2000 12 9 1 4 12 2 8 12 1 4 11 6 5 1 12 12 2 1 1 11 1 12 6 12 12 11 11 1 1 8 6 11 6 11 12 1 4 3 8 2 12 5 8 11 4 3 12 9 12 12 1 3 11 4 12 3 6 12 11 11 8 2 8 5 11 12 4 1 12 1 11 12 12 6 1 4 12 11 11 12 4 11 2 11 7 5 4 1 1 11 1 2 5 11 1 10 11 4 5 11 1 1 7 11 1 9 1 12 1 1 1 2 9 1 12 12 1 11 4 8 1 11 11 ...
output:
160524783
result:
ok single line: '160524783'
Test #46:
score: 0
Accepted
time: 40ms
memory: 130284kb
input:
2000 1 11 11 1 11 12 12 11 11 12 12 11 11 1 12 11 12 1 12 12 11 12 1 11 11 12 11 1 11 11 11 11 11 12 12 12 11 11 11 12 1 12 12 1 12 12 12 11 11 12 11 12 12 11 11 1 12 11 12 11 1 11 1 12 1 11 12 1 10 1 11 1 12 11 12 11 12 11 11 12 12 12 12 12 11 11 12 4 11 12 12 12 12 1 11 1 1 11 11 12 11 12 11 12 12...
output:
744250290
result:
ok single line: '744250290'
Test #47:
score: 0
Accepted
time: 83ms
memory: 131184kb
input:
2000 1 2 11 1 1 11 10 11 11 11 1 1 1 11 11 11 1 1 1 1 1 11 1 1 9 11 11 1 1 1 11 1 1 1 1 11 1 6 11 11 1 1 1 11 11 1 11 1 12 12 11 1 5 1 11 11 11 1 1 11 11 1 1 11 1 11 11 1 1 1 1 1 1 11 1 11 1 1 11 11 11 11 11 1 11 11 1 1 11 12 1 11 1 11 11 11 1 11 11 1 1 1 11 1 1 11 11 11 1 1 11 1 1 1 1 10 11 1 1 11 ...
output:
494588075
result:
ok single line: '494588075'
Test #48:
score: 0
Accepted
time: 43ms
memory: 132016kb
input:
2000 1 1 11 12 1 1 12 12 1 1 1 11 11 1 12 12 12 11 11 12 1 5 12 12 1 12 12 12 1 12 1 10 1 11 1 1 1 1 12 1 1 11 12 1 11 5 1 11 11 1 11 1 1 12 12 1 1 1 1 1 1 1 12 11 12 11 1 1 1 11 1 11 12 12 11 11 11 11 1 12 12 1 1 1 12 1 11 1 1 1 1 1 1 12 1 1 1 12 1 12 12 1 12 11 1 1 12 1 12 11 1 11 12 12 11 1 11 1 ...
output:
522816441
result:
ok single line: '522816441'
Test #49:
score: 0
Accepted
time: 32ms
memory: 130184kb
input:
2000 1 12 12 11 12 11 12 11 11 12 11 12 12 12 12 9 6 12 1 12 12 11 5 1 12 11 1 12 11 1 12 12 11 11 11 11 12 1 12 11 11 1 11 1 11 11 11 1 12 12 12 12 11 11 1 11 1 12 12 11 11 12 11 11 11 12 11 12 12 11 11 1 11 12 12 11 11 11 1 12 1 11 11 11 1 12 3 11 11 11 11 12 12 12 11 11 11 12 11 11 12 12 1 1 12 1...
output:
861379237
result:
ok single line: '861379237'
Test #50:
score: 0
Accepted
time: 24ms
memory: 130992kb
input:
2000 11 11 1 12 11 12 12 12 11 11 12 11 12 11 11 12 12 12 1 1 12 11 1 11 12 11 11 11 12 1 11 11 11 6 12 11 1 11 12 11 1 1 12 12 11 1 12 12 11 12 11 11 12 12 12 11 12 12 12 11 12 11 11 12 8 11 12 12 11 12 12 11 12 11 11 12 4 12 12 6 12 11 12 1 12 1 11 1 11 1 12 12 12 12 1 12 1 11 11 12 12 1 12 1 11 1...
output:
19904734
result:
ok single line: '19904734'