QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#407383 | #8228. 排序 | littleone | 100 ✓ | 2170ms | 436100kb | C++14 | 2.5kb | 2024-05-08 17:10:14 | 2024-05-08 17:10:14 |
Judging History
answer
#include <cstdio>
#include <map>
using namespace std;
const int mod = 1000000007;
int n,m,d[10],f[1048576],g[1048576],tot[11],base[10],a[10],tmp,tmp2,val[2200000],rod[2200000],nxt[2200000],st[2200000],stc,stc2;
char cst[30][2200000],tp[30][2200000];
short cost[30][2200000];
map <pair <int,int>,int> mp;
void dfs(int v,int r){
mp[make_pair(v,r)] = stc;
val[stc] = v;
rod[stc] = r;
if(r == m){
for(int i = 0;i < n;i++){
cst[i][stc] = tp[i][stc] = cost[i][stc] = -1;
}
nxt[stc] = -1;
return;
}
int to = 0,cnt,cnt2;
for(int i = 0;i < d[r];i++){
cnt = cnt2 = 0;
for(int j = i;j < n;j += d[r]){
cnt += !((v >> j) & 1);
}
for(int j = i,k = 1;j < n;j += d[r],k++){
to |= (k > cnt) << j;
cnt2 += !((v >> j) & 1);
cst[j][stc] = cnt - cnt2;
tp[j][stc] = i + (cnt - 1) * d[r];
cost[j][stc] = -1;
}
}
if(mp.find(make_pair(to,r + 1)) == mp.end()){
nxt[stc] = stc + 1;
stc++;
dfs(to,r + 1);
}
else{
nxt[stc] = mp[make_pair(to,r + 1)];
}
}
void dfs2(int v,int r){
if(r == d[0]){
st[++stc2] = ++stc;
dfs(v,0);
return;
}
dfs2(v,r + 1);
for(int i = r;i < n;i += d[0]){
v |= 1 << i;
dfs2(v,r + 1);
}
}
void dfs3(int v,int r){
if(rod[v] == m){
cost[r][v] = 0;
return;
}
if(cost[tp[r][v]][nxt[v]] < 0){
dfs3(nxt[v],tp[r][v]);
}
cost[r][v] = cost[tp[r][v]][nxt[v]] + cst[r][v];
}
int main(){
scanf("%d%d",&n,&m);
for(int i = 0;i < m;i++){
scanf("%d",&d[i]);
}
dfs2(0,0);
for(int i = 1;i <= stc2;i++){
for(int j = 0;j < n;j++){
if(!((val[st[i]] >> j) & 1)){
dfs3(st[i],j);
}
}
}
tot[0] = g[0] = 1;
for(int i = 0;i < d[0];i++){
base[i] = n / d[0] + (i + n / d[0] * d[0] < n) + 1;
tot[i + 1] = tot[i] * base[i];
}
for(int i = 0;i < tot[d[0]];i++){
tmp = i;
tmp2 = 0;
for(int j = 0;j < d[0];j++){
a[j] = tmp % base[j];
tmp /= base[j];
for(int k = j,l = 1;k < n;k += d[0],l++){
if(l <= a[j]){
tmp2 += 1 << k;
}
}
}
tmp2 = mp[make_pair(tmp2,0)];
for(int j = 0;j < d[0];j++){
if(a[j] < base[j] - 1 && f[i] + cost[j + a[j] * d[0]][tmp2] > f[i + tot[j]]){
f[i + tot[j]] = f[i] + cost[j + a[j] * d[0]][tmp2];
g[i + tot[j]] = g[i];
}
else if(a[j] < base[j] - 1 && f[i] + cost[j + a[j] * d[0]][tmp2] == f[i + tot[j]]){
g[i + tot[j]] = (g[i + tot[j]] + g[i]) % mod;
}
}
}
printf("%d %d",f[tot[d[0]] - 1],g[tot[d[0]] - 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: 0ms
memory: 22316kb
input:
2 2 2 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #2:
score: 18
Accepted
time: 0ms
memory: 40560kb
input:
5 4 5 4 2 1
output:
6 4
result:
ok 2 number(s): "6 4"
Test #3:
score: 18
Accepted
time: 0ms
memory: 59232kb
input:
8 4 6 3 2 1
output:
15 4
result:
ok 2 number(s): "15 4"
Test #4:
score: 18
Accepted
time: 3ms
memory: 59040kb
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: 3ms
memory: 59104kb
input:
8 3 8 7 1
output:
22 7
result:
ok 2 number(s): "22 7"
Test #6:
score: 18
Accepted
time: 0ms
memory: 59012kb
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: 0ms
memory: 108588kb
input:
16 2 6 1
output:
77 15
result:
ok 2 number(s): "77 15"
Test #8:
score: 27
Accepted
time: 16ms
memory: 114512kb
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: 116532kb
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: 16ms
memory: 112272kb
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: 113004kb
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: 3ms
memory: 145656kb
input:
22 3 5 3 1
output:
100 1
result:
ok 2 number(s): "100 1"
Test #13:
score: 21
Accepted
time: 0ms
memory: 145172kb
input:
22 1 1
output:
231 1
result:
ok 2 number(s): "231 1"
Test #14:
score: 21
Accepted
time: 158ms
memory: 176172kb
input:
22 4 10 8 3 1
output:
97 4
result:
ok 2 number(s): "97 4"
Test #15:
score: 21
Accepted
time: 153ms
memory: 173976kb
input:
22 5 10 7 6 3 1
output:
92 70
result:
ok 2 number(s): "92 70"
Test #16:
score: 21
Accepted
time: 151ms
memory: 176796kb
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: 164ms
memory: 176764kb
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: 7ms
memory: 96728kb
input:
14 2 10 1
output:
61 210
result:
ok 2 number(s): "61 210"
Test #19:
score: 10
Accepted
time: 0ms
memory: 120628kb
input:
18 2 2 1
output:
117 1
result:
ok 2 number(s): "117 1"
Test #20:
score: 10
Accepted
time: 871ms
memory: 341204kb
input:
30 2 9 1
output:
264 84
result:
ok 2 number(s): "264 84"
Test #21:
score: 10
Accepted
time: 686ms
memory: 308668kb
input:
29 2 9 1
output:
253 36
result:
ok 2 number(s): "253 36"
Test #22:
score: 10
Accepted
time: 100ms
memory: 191212kb
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: 2102ms
memory: 435552kb
input:
30 4 10 9 5 1
output:
188 40
result:
ok 2 number(s): "188 40"
Test #24:
score: 24
Accepted
time: 2110ms
memory: 436100kb
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: 2170ms
memory: 436004kb
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: 2169ms
memory: 434716kb
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: 2153ms
memory: 434860kb
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: 2114ms
memory: 436044kb
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: 1476ms
memory: 395104kb
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