QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#589280 | #8936. Team Arrangement | ucup-team093# | WA | 0ms | 3544kb | C++20 | 1.4kb | 2024-09-25 17:00:42 | 2024-09-25 17:00:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int N = 61;
int n, l[N], r[N], w[N];
void update(map<i64, int> &mp, i64 a, int b) {
if(!mp.count(a)) mp[a] = b;
else if(mp[a] < b) mp[a] = b;
}
int popcount(i64 x) {
return x ? popcount(x - (x & -x)) + 1 : 0;
}
int main() {
cin >> n;
for(int i = 0; i < n; i ++) {
l[i] = 1, r[i] = n;
}
for(int i = 1; i <= n; i ++) w[i] = i;
map<i64, int> mp;
mp[0] = 0;
for(int i = 1; i <= n; i ++) {
vector<int> v;
for(int j = 0; j < n; j ++) if(l[j] <= i && i <= r[j]) v.push_back(j);
sort(v.begin(), v.end(), [](int a, int b) {return r[a] < r[b];});
map<i64, int> nxt;
for(auto [idx, val] : mp) {
update(nxt, idx, val);
if(n - popcount(idx) < i) continue;
int cnt = 0;
i64 k = idx;
for(int x : v) {
if(!((idx >> x) & 1)) {
k |= 1ll << x;
cnt ++;
if(cnt == i) {
cnt = 0;
update(nxt, k, val += w[i]);
}
if(n - popcount(k) < i) break;
}
}
}
swap(nxt, mp);
}
if(mp.count((1ll << n) - 1)) cout << mp[(1ll << n) - 1];
else cout << "impossible";
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3544kb
input:
3 2 3 1 2 2 2 4 5 100
output:
3
result:
wrong answer 1st lines differ - expected: '9', found: '3'