QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#412467 | #8228. 排序 | modinte | 100 ✓ | 1275ms | 83096kb | C++14 | 1.9kb | 2024-05-16 14:52:58 | 2024-05-16 14:52:59 |
Judging History
answer
#include <bits/stdc++.h>
#define add(x, y) x = (x + y) % Mo
#define get(x, y, r) x / prod[r][y] % (lim[r][y] + 1)
const int M = 11, Mo = 1e9 + 7;
int n, m, d[M], lim[M][10], prod[M][11], a[30];
std::vector<int> f, cnt; std::vector<std::vector<int>> dp[M];
int DP(int r, int p, int mask) {
if (r == m) return 0;
if (dp[r][p][mask] != -1) return dp[r][p][mask];
for (int i = 0; i < d[r]; ++i) {
int x = get(mask, i, r);
for (int j = i; j < n; j += d[r], --x)
if (x > 0) a[j] = -1;
else if (i == p && x == 0) a[j] = 0;
else a[j] = 1;
}
dp[r][p][mask] = 0; int nxtP = -1, nxtMask = 0;
for (int i = 0; i < d[r + 1]; ++i) {
int buc[3] = {0};
for (int j = i; j < n; j += d[r + 1]) {
++buc[a[j] + 1]; if (a[j] == -1 && buc[1]) ++dp[r][p][mask];
}
if (buc[1]) nxtP = i;
nxtMask += buc[0] * prod[r + 1][i];
}
dp[r][p][mask] += DP(r + 1, nxtP, nxtMask);
return dp[r][p][mask];
}
int main() {
scanf("%d%d", &n, &m); int delta = 0;
for (int r = 1; r <= m; ++r) {
scanf("%d", &d[r]);
for (int i = 0; i < n; ++i) {
if (r == 1) delta += lim[1][i % d[r]];
++lim[r][i % d[r]];
}
prod[r][0] = 1;
for (int i = 0; i < d[r]; ++i)
prod[r][i + 1] = prod[r][i] * (lim[r][i] + 1);
dp[r].resize(d[r], std::vector<int>(prod[r][d[r]], -1));
}
f.resize(prod[1][d[1]]), cnt.resize(prod[1][d[1]]), cnt[0] = 1;
for (int mask = 0; mask < prod[1][d[1]]; ++mask)
for (int i = 0; i < d[1]; ++i) {
int x = get(mask, i, 1);
if (x == lim[1][i]) continue;
int nxtMask = mask + prod[1][i], swapCount = DP(1, i, mask);
if (f[mask] + swapCount > f[nxtMask])
f[nxtMask] = f[mask] + swapCount, cnt[nxtMask] = cnt[mask];
else if (f[mask] + swapCount == f[nxtMask])
add(cnt[nxtMask], cnt[mask]);
}
printf("%d %d", delta + f[prod[1][d[1]] - 1], cnt[prod[1][d[1]] - 1]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 18
Accepted
Test #1:
score: 18
Accepted
time: 1ms
memory: 3680kb
input:
2 2 2 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #2:
score: 18
Accepted
time: 1ms
memory: 3592kb
input:
5 4 5 4 2 1
output:
6 4
result:
ok 2 number(s): "6 4"
Test #3:
score: 18
Accepted
time: 1ms
memory: 3724kb
input:
8 4 6 3 2 1
output:
15 4
result:
ok 2 number(s): "15 4"
Test #4:
score: 18
Accepted
time: 0ms
memory: 3624kb
input:
8 6 8 7 5 4 2 1
output:
14 2
result:
ok 2 number(s): "14 2"
Test #5:
score: 18
Accepted
time: 0ms
memory: 3752kb
input:
8 3 8 7 1
output:
22 7
result:
ok 2 number(s): "22 7"
Test #6:
score: 18
Accepted
time: 0ms
memory: 3596kb
input:
8 1 1
output:
28 1
result:
ok 2 number(s): "28 1"
Subtask #2:
score: 27
Accepted
Dependency #1:
100%
Accepted
Test #7:
score: 27
Accepted
time: 2ms
memory: 3800kb
input:
16 2 6 1
output:
77 15
result:
ok 2 number(s): "77 15"
Test #8:
score: 27
Accepted
time: 14ms
memory: 4992kb
input:
16 8 10 9 8 7 6 5 4 1
output:
57 5
result:
ok 2 number(s): "57 5"
Test #9:
score: 27
Accepted
time: 14ms
memory: 4880kb
input:
16 10 10 9 8 7 6 5 4 3 2 1
output:
57 3
result:
ok 2 number(s): "57 3"
Test #10:
score: 27
Accepted
time: 14ms
memory: 4780kb
input:
16 7 10 9 8 6 5 4 1
output:
49 1
result:
ok 2 number(s): "49 1"
Test #11:
score: 27
Accepted
time: 3ms
memory: 3808kb
input:
16 4 7 6 2 1
output:
52 9
result:
ok 2 number(s): "52 9"
Subtask #3:
score: 21
Accepted
Dependency #2:
100%
Accepted
Test #12:
score: 21
Accepted
time: 0ms
memory: 3792kb
input:
22 3 5 3 1
output:
100 1
result:
ok 2 number(s): "100 1"
Test #13:
score: 21
Accepted
time: 0ms
memory: 3596kb
input:
22 1 1
output:
231 1
result:
ok 2 number(s): "231 1"
Test #14:
score: 21
Accepted
time: 109ms
memory: 9600kb
input:
22 4 10 8 3 1
output:
97 4
result:
ok 2 number(s): "97 4"
Test #15:
score: 21
Accepted
time: 107ms
memory: 8892kb
input:
22 5 10 7 6 3 1
output:
92 70
result:
ok 2 number(s): "92 70"
Test #16:
score: 21
Accepted
time: 115ms
memory: 12028kb
input:
22 6 10 9 8 7 3 1
output:
97 1
result:
ok 2 number(s): "97 1"
Test #17:
score: 21
Accepted
time: 117ms
memory: 12412kb
input:
22 10 10 9 8 7 6 5 4 3 2 1
output:
109 1
result:
ok 2 number(s): "109 1"
Subtask #4:
score: 10
Accepted
Test #18:
score: 10
Accepted
time: 5ms
memory: 3812kb
input:
14 2 10 1
output:
61 210
result:
ok 2 number(s): "61 210"
Test #19:
score: 10
Accepted
time: 0ms
memory: 3712kb
input:
18 2 2 1
output:
117 1
result:
ok 2 number(s): "117 1"
Test #20:
score: 10
Accepted
time: 579ms
memory: 25116kb
input:
30 2 9 1
output:
264 84
result:
ok 2 number(s): "264 84"
Test #21:
score: 10
Accepted
time: 463ms
memory: 20704kb
input:
29 2 9 1
output:
253 36
result:
ok 2 number(s): "253 36"
Test #22:
score: 10
Accepted
time: 77ms
memory: 6276kb
input:
25 2 8 1
output:
195 8
result:
ok 2 number(s): "195 8"
Subtask #5:
score: 24
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Test #23:
score: 24
Accepted
time: 1231ms
memory: 72280kb
input:
30 4 10 9 5 1
output:
188 40
result:
ok 2 number(s): "188 40"
Test #24:
score: 24
Accepted
time: 1248ms
memory: 83096kb
input:
30 9 10 9 8 7 6 5 4 3 1
output:
184 6
result:
ok 2 number(s): "184 6"
Test #25:
score: 24
Accepted
time: 1275ms
memory: 81696kb
input:
30 8 10 9 8 7 4 3 2 1
output:
154 1
result:
ok 2 number(s): "154 1"
Test #26:
score: 24
Accepted
time: 1232ms
memory: 64676kb
input:
30 8 10 8 7 6 5 4 3 1
output:
155 1
result:
ok 2 number(s): "155 1"
Test #27:
score: 24
Accepted
time: 1217ms
memory: 61408kb
input:
30 6 10 8 6 4 3 1
output:
150 4
result:
ok 2 number(s): "150 4"
Test #28:
score: 24
Accepted
time: 1257ms
memory: 83020kb
input:
30 10 10 9 8 7 6 5 4 3 2 1
output:
184 6
result:
ok 2 number(s): "184 6"
Test #29:
score: 24
Accepted
time: 932ms
memory: 57344kb
input:
29 6 10 9 7 5 3 1
output:
129 200
result:
ok 2 number(s): "129 200"
Extra Test:
score: 0
Extra Test Passed