QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#636450 | #8936. Team Arrangement | tarjen | TL | 0ms | 3664kb | C++20 | 1.5kb | 2024-10-12 23:56:18 | 2024-10-12 23:56:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n;
pair<int,int> ve[100];
int w[100];
int sz;
int vec[70];
int ans=0;
int cal[70];
bool check()
{
long long qu=0;
for(int i=0,now=0;i<sz;i++){
while(now<n&&ve[now].first<=vec[i]){
cal[ve[now].second]++;
qu|=1ll<<ve[now].second;
now++;
}
int x=vec[i],y=vec[i];
while(y--){
if(qu==0)return false;
int z=__builtin_ctzll(qu);
if(--cal[z]==0)qu^=1ll<<z;
if(x>z)return false;
}
}
while(qu){
int z=__builtin_ctzll(qu);
cal[z]=0;
}
return true;
}
int nowsum=0;
void dfs(int x,int cur, int n) {
if (cur == n) {
// for(auto it:vec)cout<<it<<" ";;cout<<"\n";
if (nowsum <= ans) {
return;
}
if (check()) {
ans = nowsum;
}
return ;
}
if(cur>n)return ;
for (int i = x; i<=n-cur; i++) {
vec[sz++] = i;
nowsum+=w[i];
dfs(i,cur + i, n);
--sz;
nowsum-=w[i];
}
}
int main() {
std::cin >> n;
for(int i=1;i<=n;i++){
int l,r;cin>>l>>r;
ve[i-1]=make_pair(l,r);
}
sort(ve,ve+n);
for(int i=1;i<=n;i++)cin>>w[i];
int inf=1e9;
ans=-inf;
dfs(1,0,n);
if(ans!=-inf)std::cout << ans << std::endl;
else cout<<"impossible\n";
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
input:
3 2 3 1 2 2 2 4 5 100
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3456kb
input:
3 1 3 3 3 2 3 1 1 100
output:
100
result:
ok single line: '100'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
2 1 1 2 2 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
3 2 3 1 2 2 2 -100 -200 100000
output:
-300
result:
ok single line: '-300'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3456kb
input:
9 1 4 2 5 3 4 1 5 1 1 2 5 3 5 1 3 1 1 1 1 1 1 1 1 1 1 1
output:
6
result:
ok single line: '6'
Test #6:
score: -100
Time Limit Exceeded
input:
14 3 3 1 2 2 3 2 3 2 3 1 1 2 3 1 3 3 3 1 3 1 3 1 2 2 3 1 3 -9807452 -9610069 4156341 2862447 6969109 -7245265 -2653530 -5655094 6467527 -6872459 3971784 7312155 9766298 -2719573