QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#636531 | #6143. 滚榜 | propane | 50 | 179ms | 46984kb | C++20 | 3.0kb | 2024-10-13 00:20:09 | 2024-10-13 00:20:11 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<numeric>
#include<map>
#include<algorithm>
using namespace std;
using LL = long long;
map<pair<int, int>, LL> dp[13][1 << 13];
int f[1 << 13][500];
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<int> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
pair<int, int> mx{0, 0};
for(int i = 0; i < n; i++){
mx = max(mx, make_pair(a[i], -i));
}
for(int i = 0; i < n; i++){
int need = mx.first - a[i];
if (make_pair(a[i] + need, -i) < mx){
need += 1;
}
if (need * n <= m) dp[i][1 << i][{need, need}] = 1;
}
auto get = [&](int state, int last){
vector<int> v;
for(int i = 0; i < n; i++){
if (!(state >> i & 1)){
v.push_back(i);
}
}
int l = 0, r = 0;
for(auto x : v){
l += a[last] - a[x];
}
sort(v.begin(), v.end(), [&](int x, int y){
return a[x] < a[y];
});
{
vector<int> nv;
for(int i = 0, j = n - 1; i <= j; i++, j--){
nv.push_back(i);
if (i != j) nv.push_back(j);
}
v.swap(nv);
}
int lastval = a[last];
int val = -1e9;
for(auto x : v){
int need = max(lastval + 1 - a[x], val + 1);
r += need;
val = need;
lastval = a[x] + need;
}
return make_pair(l, r);
};
LL fact[14];
fact[0] = 1;
for(int i = 1; i <= 13; i++) fact[i] = fact[i - 1] * i;
LL ans = 0;
for(int i = 1; i + 1 < 1 << n; i++){
int c = __builtin_popcount(i);
for(int j = 0; j < n; j++){
auto [l, r] = get(i, j);
for(auto &[par, cnt] : dp[j][i]){
auto [last, sum] = par;
if (sum + l + last * (n - c) > m){
continue;
}
if (sum + r + last * (n - c) <= m){
ans += fact[n - c] * cnt;
continue;
}
pair<int, int> mx = {a[j] + last, -j};
for(int k = 0; k < n; k++){
if (i >> k & 1) continue;
int need = max(last, a[j] + last - a[k]);
if (pair(a[k] + need, -k) < mx){
need += 1;
}
if ((n - c) * need + sum <= m){
dp[k][i | (1 << k)][{need, need + sum}] += cnt;
}
}
}
}
}
for(int i = 0; i < n; i++){
for(auto &[par, cnt] : dp[i][(1 << n) - 1]){
ans += cnt;
}
}
cout << ans << '\n';
}
詳細信息
Pretests
Final Tests
Test #1:
score: 5
Accepted
time: 3ms
memory: 10432kb
input:
2 8 8950 8954
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 5
Accepted
time: 3ms
memory: 9844kb
input:
2 10 8841 8843
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 5
Accepted
time: 3ms
memory: 10420kb
input:
3 9 8765 8761 8765
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 5
Accepted
time: 0ms
memory: 10200kb
input:
3 8 8385 8385 8387
output:
6
result:
ok 1 number(s): "6"
Test #5:
score: 5
Accepted
time: 3ms
memory: 9556kb
input:
3 9 8581 8585 8582
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 5
Accepted
time: 8ms
memory: 11532kb
input:
8 100 8856 8864 8858 8860 8856 8863 8859 8857
output:
17589
result:
ok 1 number(s): "17589"
Test #7:
score: 5
Accepted
time: 10ms
memory: 11980kb
input:
8 100 8238 8239 8245 8244 8245 8244 8238 8244
output:
32475
result:
ok 1 number(s): "32475"
Test #8:
score: 0
Wrong Answer
time: 4ms
memory: 11148kb
input:
8 100 9804 9806 9807 9802 9801 9803 9801 9806
output:
37036
result:
wrong answer 1st numbers differ - expected: '37012', found: '37036'
Test #9:
score: 5
Accepted
time: 75ms
memory: 30048kb
input:
10 200 8002 8014 8011 8013 8002 8003 8002 8016 8009 8004
output:
606309
result:
ok 1 number(s): "606309"
Test #10:
score: 5
Accepted
time: 140ms
memory: 40356kb
input:
10 200 8324 8323 8328 8322 8325 8328 8328 8323 8334 8323
output:
2504995
result:
ok 1 number(s): "2504995"
Test #11:
score: 0
Wrong Answer
time: 2ms
memory: 9304kb
input:
10 200 9416 9415 9417 9404 9408 9409 9410 9416 9415 9411
output:
3628800
result:
wrong answer 1st numbers differ - expected: '2553164', found: '3628800'
Test #12:
score: 5
Accepted
time: 179ms
memory: 46984kb
input:
10 200 9422 9430 9425 9425 9425 9423 9431 9428 9432 9434
output:
2687280
result:
ok 1 number(s): "2687280"
Test #13:
score: 0
Time Limit Exceeded
input:
12 300 9281 9292 9279 9280 9289 9291 9285 9279 9280 9281 9290 9281
output:
result:
Test #14:
score: 0
Time Limit Exceeded
input:
12 300 9737 9726 9731 9736 9723 9727 9722 9732 9736 9733 9737 9728
output:
result:
Test #15:
score: 0
Time Limit Exceeded
input:
12 300 8707 8708 8712 8704 8705 8704 8716 8711 8713 8712 8702 8710
output:
result:
Test #16:
score: 0
Time Limit Exceeded
input:
12 300 9200 9194 9191 9195 9197 9192 9206 9206 9197 9198 9192 9202
output:
result:
Test #17:
score: 0
Time Limit Exceeded
input:
13 500 8217 8233 8238 8217 8237 8237 8217 8217 8230 8234 8225 8223 8220
output:
result:
Test #18:
score: 0
Time Limit Exceeded
input:
13 500 9781 9780 9772 9779 9785 9788 9788 9777 9791 9784 9782 9777 9768
output:
result:
Test #19:
score: 0
Time Limit Exceeded
input:
13 500 8096 8078 8103 8104 8085 8089 8081 8085 8102 8095 8097 8100 8090
output:
result:
Test #20:
score: 0
Time Limit Exceeded
input:
13 500 8739 8728 8743 8727 8730 8735 8733 8738 8731 8743 8728 8722 8722