QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#277783 | #7886. Not Another Eulerian Number Problem | Zaoly | TL | 136ms | 3596kb | C++14 | 1.4kb | 2023-12-06 22:49:15 | 2023-12-06 22:49:17 |
Judging History
answer
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int N = 10;
int alpha, n, m, n0;
int subperm[N], oriperm[N];
bool next_oriperm()
{
for (int i = 0; i < n * alpha; ++i)
if (oriperm[i] < n)
{
++oriperm[i];
return true;
}
else
oriperm[i] = 1;
return false;
}
bool is_order_perm()
{
int occurs[N + 1]{};
for (int i = 0; i < n * alpha; ++i)
++occurs[oriperm[i]];
for (int i = 1; i <= n; ++i)
if (occurs[i] != alpha)
return false;
for (int i = 0; i < n * alpha; ++i)
for (int j = i + 1; j < n * alpha; ++j)
{
if (oriperm[i] != oriperm[j])
continue;
for (int k = i + 1; k < j; ++k)
if (oriperm[k] < oriperm[i])
return false;
}
return true;
}
bool is_subseq()
{
int ptr = 0;
for (int i = 0; i < n * alpha; ++i)
if (ptr < n0 * alpha && oriperm[i] == subperm[ptr])
++ptr;
return ptr == n0 * alpha;
}
bool check_indices()
{
int greater_cnt = 0;
for (int i = 0; i < n * alpha - 1; ++i)
if (oriperm[i] > oriperm[i + 1])
++greater_cnt;
return greater_cnt == m;
}
int main()
{
int result = 0;
cin >> alpha >> n >> m >> n0;
for (int i = 0; i < n0 * alpha; ++i)
cin >> subperm[i];
for (int i = 0; i < n * alpha; ++i)
oriperm[i] = 1;
do
if (is_order_perm() && is_subseq() && check_indices())
++result;
while (next_oriperm());
cout << result << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3432kb
input:
1 4 2 2 2 1
output:
7
result:
ok 1 number(s): "7"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
2 4 2 2 1 2 2 1
output:
19
result:
ok 1 number(s): "19"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3372kb
input:
1 1 0 1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3320kb
input:
3 1 0 1 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3388kb
input:
4 1 0 1 1 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3388kb
input:
5 1 0 1 1 1 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
10 1 0 1 1 1 1 1 1 1 1 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3420kb
input:
1 3 2 1 1
output:
1
result:
ok 1 number(s): "1"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3376kb
input:
3 3 2 3 2 2 2 3 3 3 1 1 1
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 0
Accepted
time: 1ms
memory: 3480kb
input:
3 3 2 2 1 1 2 2 2 1
output:
5
result:
ok 1 number(s): "5"
Test #11:
score: 0
Accepted
time: 1ms
memory: 3384kb
input:
3 3 2 1 1 1 1
output:
15
result:
ok 1 number(s): "15"
Test #12:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
3 3 1 2 2 2 2 1 1 1
output:
2
result:
ok 1 number(s): "2"
Test #13:
score: 0
Accepted
time: 1ms
memory: 3560kb
input:
1 4 0 4 4 2 1 3
output:
0
result:
ok 1 number(s): "0"
Test #14:
score: 0
Accepted
time: 1ms
memory: 3552kb
input:
2 4 1 4 1 4 4 3 3 2 2 1
output:
0
result:
ok 1 number(s): "0"
Test #15:
score: 0
Accepted
time: 1ms
memory: 3440kb
input:
2 4 2 4 1 3 3 2 2 4 4 1
output:
1
result:
ok 1 number(s): "1"
Test #16:
score: 0
Accepted
time: 1ms
memory: 3428kb
input:
2 4 2 1 1 1
output:
58
result:
ok 1 number(s): "58"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3396kb
input:
2 4 1 2 1 1 2 2
output:
14
result:
ok 1 number(s): "14"
Test #18:
score: 0
Accepted
time: 136ms
memory: 3552kb
input:
1 8 7 3 2 1 3
output:
0
result:
ok 1 number(s): "0"
Test #19:
score: 0
Accepted
time: 135ms
memory: 3376kb
input:
1 8 0 4 1 2 3 4
output:
1
result:
ok 1 number(s): "1"
Test #20:
score: 0
Accepted
time: 131ms
memory: 3316kb
input:
1 8 4 4 4 3 1 2
output:
771
result:
ok 1 number(s): "771"
Test #21:
score: 0
Accepted
time: 136ms
memory: 3532kb
input:
1 8 1 4 4 3 2 1
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 0
Accepted
time: 128ms
memory: 3384kb
input:
1 8 7 1 1
output:
1
result:
ok 1 number(s): "1"
Test #23:
score: -100
Time Limit Exceeded
input:
1 9 2 5 4 3 1 5 2