QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#848880 | #8228. 排序 | lyx123886a123886 | 100 ✓ | 3265ms | 141196kb | C++14 | 2.5kb | 2025-01-09 10:23:11 | 2025-01-09 10:23:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define dec(i,a,b) for(int i=(a);i>=(b);--i)
using ll=long long;
using pi=pair<int,int>;
using vi=vector<int>;
using vp=vector<pi>;
template<class T> bool chkmin(T &x,T y) {return (y<x)?(x=y,true):false;}
template<class T> bool chkmax(T &x,T y) {return (y>x)?(x=y,true):false;}
#define pb push_back
#define SZ(x) int(x.size())
#define fi first
#define se second
#define LOCAL 0
#define open_file if(LOCAL) {freopen("b.in","r",stdin);freopen("b.out","w",stdout);}
#define Bit(i) (1<<(i))
#define bit(s,i) (((s)>>(i))&1)
int read() {int x;scanf("%d",&x);return x;}
const int MAXN=30;
const int mod=1e9+7;
#define look_time cerr<<(1.0*clock()/CLOCKS_PER_SEC)<<"\n";
void add(int &x,int T) {x+=T;if(x>=mod) x-=mod;}
using info=pi;
void operator +=(info &x,const info &y) {
if(y.fi>x.fi) x=y;
else if(y.fi==x.fi) add(x.se,y.se);
}
info operator +(info x,const int &k) {
x.fi+=k;return x;
}
int n,m,D;
int stp[15];
namespace shell_sort {
int A[35];int len,t;
int swap_count;
void work() {
rep(pos,t,len-1) for(int j=pos;j>=t&&A[j]<A[j-t];j-=t) swap(A[j],A[j-t]),swap_count+=(A[j]==1);
}
int sh(int bs,int sp) {
rep(i,0,n-1) A[i]=bit(bs,i)<<1;A[sp]=1;
len=n,swap_count=0;
dec(i,m,1) {
t = stp[i];
work();
}
return swap_count;
}
};
using shell_sort::sh;
void show(pi nw) {
rep(i,0,n-1) if(i==nw.se) putchar('*');
else putchar('0'+bit(nw.fi,i));
puts("");
}
vector<pair<pi,int>> tr;
void dfs(int rem,int bs) {
if(rem==D) {
rep(pos,0,n-1) if(!bit(bs,pos)&&(pos+D>=n||bit(bs,pos+D))) tr.pb({pi(bs,pos),sh(bs,pos)});
return ;
}
int num=(n-1-rem)/D;// pos::[0,num]*D+rem
rep(ps,0,num+1) {
int nxt=bs;
rep(i,ps,num) nxt|=Bit(rem+i*D);
dfs(rem+1,nxt);
}
}
void get_base() {dfs(0,0);}
unordered_map<int,info> dp;
int c2(int x) {return x*(x-1)/2;}
void solve() {
n=read(),m=read();
dec(i,m,1) scanf("%d",stp+i);
D=stp[m--];
tr.reserve(8e6);
get_base();look_time
dp[0]={0,1};//!!
sort(tr.begin(),tr.end());
for(auto &[bs,delt]:tr) {
dp[bs.fi|Bit(bs.se)]+=(dp[bs.fi]+delt);
}
pi ans=dp[Bit(n)-1];
rep(rem,0,D-1) ans.fi+=c2((n-1-rem)/D+1);//!
printf("%d %d\n",ans.fi,ans.se);
}
int main() {
open_file
for(int test_case=1;test_case;test_case--) solve();
look_time
return 0;
}
详细
Subtask #1:
score: 18
Accepted
Test #1:
score: 18
Accepted
time: 0ms
memory: 4172kb
input:
2 2 2 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #2:
score: 18
Accepted
time: 0ms
memory: 3936kb
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: 3960kb
input:
8 4 6 3 2 1
output:
15 4
result:
ok 2 number(s): "15 4"
Test #4:
score: 18
Accepted
time: 1ms
memory: 3940kb
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: 1ms
memory: 4004kb
input:
8 3 8 7 1
output:
22 7
result:
ok 2 number(s): "22 7"
Test #6:
score: 18
Accepted
time: 0ms
memory: 3952kb
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: 4264kb
input:
16 2 6 1
output:
77 15
result:
ok 2 number(s): "77 15"
Test #8:
score: 27
Accepted
time: 16ms
memory: 6604kb
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: 10ms
memory: 4956kb
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: 15ms
memory: 4920kb
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: 4ms
memory: 4172kb
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: 5ms
memory: 4356kb
input:
22 3 5 3 1
output:
100 1
result:
ok 2 number(s): "100 1"
Test #13:
score: 21
Accepted
time: 0ms
memory: 4060kb
input:
22 1 1
output:
231 1
result:
ok 2 number(s): "231 1"
Test #14:
score: 21
Accepted
time: 169ms
memory: 16912kb
input:
22 4 10 8 3 1
output:
97 4
result:
ok 2 number(s): "97 4"
Test #15:
score: 21
Accepted
time: 181ms
memory: 18000kb
input:
22 5 10 7 6 3 1
output:
92 70
result:
ok 2 number(s): "92 70"
Test #16:
score: 21
Accepted
time: 179ms
memory: 18296kb
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: 226ms
memory: 17796kb
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: 4368kb
input:
14 2 10 1
output:
61 210
result:
ok 2 number(s): "61 210"
Test #19:
score: 10
Accepted
time: 0ms
memory: 4184kb
input:
18 2 2 1
output:
117 1
result:
ok 2 number(s): "117 1"
Test #20:
score: 10
Accepted
time: 891ms
memory: 66804kb
input:
30 2 9 1
output:
264 84
result:
ok 2 number(s): "264 84"
Test #21:
score: 10
Accepted
time: 705ms
memory: 57308kb
input:
29 2 9 1
output:
253 36
result:
ok 2 number(s): "253 36"
Test #22:
score: 10
Accepted
time: 109ms
memory: 13704kb
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: 2212ms
memory: 140032kb
input:
30 4 10 9 5 1
output:
188 40
result:
ok 2 number(s): "188 40"
Test #24:
score: 24
Accepted
time: 3044ms
memory: 140476kb
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: 2894ms
memory: 139756kb
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: 2963ms
memory: 140096kb
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: 2634ms
memory: 139744kb
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: 3265ms
memory: 141196kb
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: 1819ms
memory: 112040kb
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