QOJ.ac
QOJ
QOJ is currently under a maintenance. It might be unavailable in the following a few hours.
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#892093 | #7976. 最后的晚餐 | Fffoooo | 100 ✓ | 561ms | 479520kb | C++14 | 9.0kb | 2025-02-09 22:03:16 | 2025-02-09 22:03:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int mian(); int main() { return mian(); }
#define ll long long
const int N = 2005, NA = N * 12;
const int mod = 998244353;
int n, cnt[N], _;
int h[2][N][NA], sum[N][NA];
void init_h(const int op) {
int s_m = 0, s_s = 0;
h[op & 1][0][0] = 1;
for(int x = op; x <= 12; x += 2) {
s_m += cnt[x]; s_s += cnt[x] * x;//注意需要先增加,否则前缀和不能到达
for(int m = 0; m <= s_m; ++m) for(int s = 0; s <= s_s; ++s)
sum[m][s] = (h[op & 1][m][s] + ( m and s >= x ? sum[m - 1][s - x] : 0 )) % mod;
for(int m = 0; m <= s_m; ++m) for(int s = 0; s <= s_s; ++s)
h[op & 1][m][s] = (sum[m][s] - ( m > cnt[x] and s >= (cnt[x] + 1) * x ? sum[m - cnt[x] - 1][s - (cnt[x] + 1) * x] : 0 ) + mod) % mod;
//注意判断中也要注意范围
}
// cout<<op<<endl;
// for(int m = 0; m <= s_m; ++m, puts("")) for(int s = 0; s <= s_s; ++s) cout<<h[op][m][s]<<" ";
// puts("");
}
int sum2[N][NA];//, sum3[N][NA];卡空间
#define sum1 sum
void init_h1() {
memset(sum, 0, sizeof sum);
int s_m = 0, s_s = 0;
for(int x = 3; x <= 12; x += 2) s_m += cnt[x], s_s += cnt[x] * x;//不要写错
for(int m = 0; m <= s_m; ++m) {
for(int s = 0; s <= s_s; ++s) {
if(m >= cnt[1]) {
sum1[m][s] = (sum1[m][s] + h[1][m][s]) % mod;//卡空间将 3 改为 1
sum1[m + cnt[1] + 1][s + cnt[1] + 1] = (sum1[m + cnt[1] + 1][s + cnt[1] + 1] + mod - h[1][m][s]) % mod;
continue;//需要特判超过范围的m
}
sum1[m][s] = (sum1[m][s] + h[1][m][s]) % mod;
sum1[m + m][s + m] = (sum1[m + m][s + m] + mod - h[1][m][s]) % mod;//对于 $d\lt m$ 的部分,没有减去东西,这一部分中所有状态可以获得
const int same = (cnt[1] - m) / 2 + 1, diff = (cnt[1] - m + 1) / 2;//分别表示与 $m$ 奇偶性相同与不同的 $d$ 的数量
sum2[m + m][s + m] = (sum2[m + m][s + m] + h[1][m][s]) % mod;
sum2[m + m + same][s + m + same * 2] = (sum2[m + m + same][s + m + same * 2] + mod - h[1][m][s]) % mod;
//此后的变化中,m 一项增加的是\frac{d-m}{2},而 $s$ 一项则会增加整个 $d$,直接变成两倍
//注意对于奇偶性相同的要考虑算上自身,所以直接增加 same 就是减少-1
sum2[m + m][s + m + 1] = (sum2[m + m][s + m + 1] + h[1][m][s]) % mod;
sum2[m + m + diff][s + m + 1 + diff * 2] = (sum2[m + m + diff][s + m + 1 + diff * 2] + mod - h[1][m][s]) % mod;
//注意当奇偶性不同时前者的变化要少 $1$,后者不变。注意实际上的 $d$ 应该是 $d+m$,所以后面是 $m+d*2$
//注意这里同样会发现也是需要减少 $1$,因为有了一个增加 $1$
}
}
s_m += cnt[1]; s_s += cnt[1];
for(int m = 1; m <= s_m; ++m) for(int s = 1; s <= s_s; ++s) {
sum1[m][s] = (sum1[m][s] + sum1[m - 1][s - 1]) % mod;
if(s >= 2) sum2[m][s] = (sum2[m][s] + sum2[m - 1][s - 2]) % mod;
// sum3[m][s] = (sum3[m][s] + sum3[m - 1][s - 2]) % mod;
}
for(int m = 0; m <= s_m; ++m) for(int s = 0; s <= s_s; ++s)
h[1][m][s] = ( (ll)sum1[m][s] + sum2[m][s] ) % mod;//注意不用加入 h[3]
// cout<<1<<endl;
// for(int m = 0; m <= s_m; ++m, puts("")) for(int s = 0; s <= s_s; ++s) cout<<h[1][m][s]<<" ";
// puts("");
}
int val1[NA][10], val0[NA][10];
int getans() {
int ans = 0, s_m1 = 0, s_s1 = 0, s_s0 = 0, s_m0 = 0;
for(int x = 1; x <= 12; x += 2) s_m1 += cnt[x], s_s1 += cnt[x] * x;
for(int x = 2; x <= 12; x += 2) s_m0 += cnt[x], s_s0 += cnt[x] * x;
int all1 = 0, all0 = 0, ALL = n + 1;
// cout<<s_m0<<" "<<s_s0<<endl;
for(int m = 0; m <= s_m0; ++m) for(int s = 0; s <= s_s0; ++s) all0 = (all0 + h[0][m][s]) % mod;
for(int m = 0; m <= s_m1; ++m) for(int s = 0; s <= s_s1; ++s) all1 = (all1 + h[1][m][s]) % mod;
//不要写混 m,s
// cout<<all0<<" "<<all1<<endl;
for(int m = 0; m <= s_m0; ++m) for(int s = 0; s <= s_s0; ++s) {
ans = ( ans + (ll)all1 * m % mod * h[0][m][s] % mod ) % mod;
val0[s / 10 - m + ALL][s % 10] = (val0[s / 10 - m + ALL][s % 10] + h[0][m][s]) % mod;
}
for(int m = 0; m <= s_m1; ++m) for(int s = 0; s <= s_s1; ++s) {
ans = ( ans + (ll)all0 * (m + 1) % mod * h[1][m][s] % mod ) % mod;//注意答案的增加 $1$
val1[s / 10 - m + ALL][s % 10] = (val1[s / 10 - m + ALL][s % 10] + h[1][m][s]) % mod;
}//需要注意到 $\lfloor\frac{A+B}{C}\rfloor=\lfloor\frac{A}{C}\rfloor+\lfloor\frac{B}{C}\rfloor+[A\mod C+B\mod C\gt C]$
// cout<<ans<<endl;
for(int p = - s_m0; p <= s_s0 / 10; ++p) {
for(int i = 0; i < 10; ++i) {
if(!val0[p + ALL][i]) continue;
for(int q = - s_m1; q <= s_s1 / 10; ++q) {
if(p + q >= 0) break;
for(int j = 0; j < 10; ++j) {
if( val1[q + ALL][j] and (p + q + (i + j) / 10) < 0 )
ans = (ans + (ll)val0[p + ALL][i] * val1[q + ALL][j] % mod * ( mod + p + q + (i + j) / 10 ) % mod) % mod;
}
}
}
}
return ans;
}
int mian() {
// freopen("125.in", "r", stdin);
_ = scanf("%d", &n);
for(int i = 1, a; i <= n; ++i) _ = scanf("%d", &a), cnt[a]++;
init_h(0); init_h(3);
init_h1();
int ans = getans();
printf("%d\n", ans);
return 0;
}/*
对于一个集合 $A$,将其内部元素按任意顺序排序后得到 $a_{1\to n}$。
设 $b_{i\in [0,n]}=\sum \lfloor\frac{\sum _{j=1}^i a_j}{10}\rfloor$。
令 $f(A)$ 表示所有可能的顺序下,最大的 $b$ 中不同数字数量。
给定集合 $A$,求出所有 $A$ 的本质不同的子集 $B$ 的 $f(B)$ 之和。
$n\le 2000, 1\le a_i\le 12, mod=998244353$
$1s, 512MB$
假设 $f(B)=f(B)-1$,这样就不用考虑 $b_i=0$ 的情况
考虑已知 $B$ 的情况下求出 $f(B)$。那么发现答案上界会是 $\min(n,\lfloor\frac{S}{10}\rfloor)$,原因显然
能否取到这个上界呢?在 $a_i\le 11$ 的时候,有以下策略:
- 如果发现的当前前缀和末尾不为 $9$,且还有 $11$,填充 $11$
- 否则任意填充
- 当发现没有 $11$,那么说明后面所有数字都不会直接使得向下取整增加 $2$,答案取到右侧;否则每个数字都会产生一次进位,取到左侧
---
但是发现,对于 $a_i\le 12$,会存在问题,如 ${1,12,12,12,12}$ 的情况。这是因为当末尾为 $8$ 时,$1$ 依然不能产生进位
那么如果只有偶数和 $1$,所有的 $1$ 只有两两配对之后才可能进位,答案上界为 $\min(n-\lceil\frac{c_1}{2}\rceil,\lfloor\frac{S}{10}\rfloor)$
进一步的,$1$ 进位的先决条件是当前的前缀和末尾为 $9$,那么如果全部都是偶数就无法进位,而每个奇数都可以用来调整这个奇偶性,
可以通过加入一个奇数并加入一些偶数,最后加入一个 $1$ 满足进位
于是此时仍然不能进位的 $1$ 有 $\max(c_1-(c_3+c_5+c_7+c_9+c_{11}),0)$ 个,他们必须两两配对组成 $2$。
因此答案上界就是 $\min(n-\lceil\frac{\max(c_1-(c_3+c_5+c_7+c_9+c_{11}),0)}{2}\rceil,\lfloor\frac{S}{10}\rfloor)$。
仿照用以下策略得到:
- 如果当前前缀和末尾 $\lt 8$:优先填充 $12$;如果没有 $12$,按照没有 $12$ 的子问题填充
- 如果当前前缀和末尾为 $8$:优先填充不是 $12$ 的偶数;如果没有,优先填充 $11$;如果还是没有,优先填充一个不为 $1$ 的奇数;
最后都没有,填充 $1$(如果只剩下了 $12$,那么后面的每个 $12$ 都会自带进位,不用讨论)
- 如果当前末尾为 $9$:优先填充 $1$;没有就任意填充(如果全部剩下 $11,12$ 同上自带进位,不用讨论)
于是会发现除了 $1$ 以外的所有数字都会产生进位,且当出现第二种情况中最后一种时,就说明只剩下 $12$ 和 $1$,
答案为 $\min(n-\lceil\frac{c_1}{2}\rceil,\lfloor\frac{S}{10}\rfloor)$。
于是总的答案就是 $\min(n-\lceil\frac{\max(c_1-(c_3+c_5+c_7+c_9+c_{11}),0)}{2}\rceil,\lfloor\frac{S}{10}\rfloor)$。
---
求解答案,因为分奇偶性,可以分别求出 `h0[m][s],h3[m][s]` 分别表示对于 $A$ 中只含有偶数/大于 $1$ 的奇数,当前集合内一共有 $m$ 个数字,总和为 $s$ 的方案数
求解可以枚举每种数字 $x$,然后枚举 $x$ 的选取次数并转移。
会发现对于一个 $h[m][s]$,其只能从 $h[m-i][s-ix]$ 转移,于是记录前缀和为 $sum[m][s]+=sum[m-i][s-ix]$ 即可做到 $O(n^2|a|)$ 求出
那么答案就是 $\sum_{d_1,s_1,m_1,s_0,m_0}h_{0,m_0,s_0}h_{3,m_1,s_1}(\min(m_1+m_0+d_1-\max(0,\lceil\frac{d_1-m_1}{2}\rceil),
\lfloor\frac{s_0+s_1+d_1}{10}\rfloor)+1)$ 注意原本的 $f$ 减少了一个 $1$
---
优化,尝试将 $d_1$ 和 $h_1$ 合并,于是有 $h_{3,m_1,s_1}\to h_{1,m_1+d_1-\lceil\frac{\max(0,d_1-m_1)}{2}\rceil),s_1+d_1}$。
具体的,分别讨论 $m_1,d_1$ 的大小关系,然后类似前面用前缀和优化转移做到 $O(n^2|a|)$
此时答案变成 $\sum h_{0,m_0,s_0}h_{1,m_1,s_1}(1+\min(m_0+m_1,\lfloor\frac{s_0+s_1}{10}\rfloor))$。
可以先求出所有答案都取到左侧时的答案,然后只需要减去所有不满足条件的点的差值即可
需要注意到 $\lfloor\frac{A+B}{C}\rfloor=\lfloor\frac{A}{C}\rfloor+\lfloor\frac{B}{C}\rfloor+[A\mod C+B\mod C\gt C]$
所以要分其 $s$ 的余数来讨论。总复杂度 $O(100n^2+n^2\times |a|)$
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 4
Accepted
Test #1:
score: 4
Accepted
time: 5ms
memory: 196436kb
input:
5 1 1 4 5 1 4
output:
19
result:
ok single line: '19'
Test #2:
score: 4
Accepted
time: 5ms
memory: 196400kb
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: 4
Accepted
time: 4ms
memory: 196432kb
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: 4
Accepted
time: 9ms
memory: 198560kb
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: 6ms
memory: 196216kb
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: 12
Accepted
time: 9ms
memory: 196368kb
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: 12
Accepted
time: 5ms
memory: 196492kb
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: 12
Accepted
time: 10ms
memory: 198576kb
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: 12
Accepted
time: 4ms
memory: 196656kb
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: 12
Accepted
time: 8ms
memory: 198616kb
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: 12
Accepted
time: 8ms
memory: 196696kb
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: 12
Accepted
time: 6ms
memory: 198596kb
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: 6ms
memory: 197824kb
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: 16
Accepted
time: 261ms
memory: 296532kb
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: 16
Accepted
time: 350ms
memory: 354488kb
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: 16
Accepted
time: 561ms
memory: 479520kb
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: 13ms
memory: 199996kb
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: 12
Accepted
time: 265ms
memory: 287060kb
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: 12
Accepted
time: 312ms
memory: 328304kb
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: 12
Accepted
time: 287ms
memory: 315332kb
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: 12
Accepted
time: 330ms
memory: 326412kb
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: 5ms
memory: 196944kb
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: 12
Accepted
time: 5ms
memory: 197144kb
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: 12
Accepted
time: 9ms
memory: 196856kb
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: 12
Accepted
time: 9ms
memory: 199096kb
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: 12
Accepted
time: 7ms
memory: 199344kb
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: 4ms
memory: 201068kb
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: 8
Accepted
time: 15ms
memory: 201556kb
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: 8
Accepted
time: 15ms
memory: 200776kb
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: 8
Accepted
time: 13ms
memory: 205856kb
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: 8
Accepted
time: 9ms
memory: 206076kb
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: 8
Accepted
time: 15ms
memory: 213512kb
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: 8
Accepted
time: 12ms
memory: 211712kb
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: 199416kb
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: 12
Accepted
time: 29ms
memory: 212380kb
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: 12
Accepted
time: 33ms
memory: 211172kb
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: 12
Accepted
time: 24ms
memory: 218448kb
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: 12
Accepted
time: 29ms
memory: 220316kb
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: 12
Accepted
time: 46ms
memory: 237564kb
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: 12
Accepted
time: 22ms
memory: 229980kb
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: 12
Accepted
time: 31ms
memory: 218788kb
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: 10ms
memory: 199392kb
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: 24
Accepted
time: 266ms
memory: 296124kb
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: 24
Accepted
time: 310ms
memory: 338284kb
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: 24
Accepted
time: 243ms
memory: 320908kb
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: 24
Accepted
time: 281ms
memory: 346252kb
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: 24
Accepted
time: 348ms
memory: 429808kb
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: 24
Accepted
time: 182ms
memory: 357088kb
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: 24
Accepted
time: 272ms
memory: 341000kb
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: 24
Accepted
time: 265ms
memory: 332820kb
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'