QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#628536#8936. Team Arrangementucup-team1266#WA 0ms3732kbC++201.5kb2024-10-10 20:50:032024-10-10 20:50:04

Judging History

This is the latest submission verdict.

  • [2024-10-10 20:50:04]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3732kb
  • [2024-10-10 20:50:03]
  • Submitted

answer

#include<bits/stdc++.h>
#define ll long long
using ull = unsigned long long;
#define pii array<ll,2>
#define endl '\n'
using namespace std;
const int N=4e5+5;

int k;
int a[65],tmp[65];
array<int,2>man[65];    //man[i][0]是r [i][1]是l
ll w[65];
int n;
ll lowbit(ll x){
    return x&-x;
}
bool check(ll &live,int k){ //当前剩余live人和该组分配k人
    ll tmp=live,cnt=0;
    while(tmp&&cnt<k){
        ll x=lowbit(tmp),tp=log2(x)+1;
        if(man[tp][1]<=k&&k<=man[tp][0]){
            cnt++;
            live-=x;
        }
        //cout<<live<<' '<<tmp<<' '<<tp<<endl;
        tmp-=x;
    }
    return cnt==k;
}
ll dfs(int rem,int lst,int len,ll liv){
    ll res=-1e9;
    if(rem==0){
        res=0;
        for(int i=1;i<len;i++) res+=w[a[i]];
        return res;
    } 
    for(int i=1;i<=lst&&rem-i>=0;i++){
        a[len]=i;
        ll nliv=liv;
        if(!check(nliv,i)) continue;
        res=max(res,dfs(rem-i,i,len+1,nliv));
        a[len]=0;
    }
    return res;
}
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>man[i][1]>>man[i][0];
    sort(man+1,man+n+1,greater<>());
    //for(int i=1;i<=n;i++) cout<<man[i][1]<<' '<<man[i][0]<<endl;
    for(int i=1;i<=n;i++) cin>>w[i];
    ll res=dfs(n,n,1,(1LL<<n)-1);
    if(res==-1e9){
        cout<<"impossible";
        return;
    }
    cout<<res;
}
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    // int T=1;cin>>T;while(T--) 
    solve();
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3708kb

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: 3652kb

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: 3732kb

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

3
2 3
1 2
2 2
-100 -200 100000

output:

-300

result:

ok single line: '-300'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3732kb

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:

5

result:

wrong answer 1st lines differ - expected: '6', found: '5'