QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#666593 | #8936. Team Arrangement | lytqwq# | WA | 0ms | 3724kb | C++14 | 1.7kb | 2024-10-22 19:14:19 | 2024-10-22 19:14:32 |
Judging History
answer
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<functional>
using namespace std;
#define Inf 0x7fffffff
int n;
int a[65];
int s[65];
int res=0;
vector<int>ed[65],bf[65];
int stk[65],lens;
int L[65],R[65];
int b[65];
int work(){
int add=0;
for(int i=1;i<=n;i++)b[i]=0;
int cnt=0;
int ned=0,has=0;
for(int i=1;i<=n;i++){
int ress=0;
for(auto&x:ed[i]){
if(i==x)ress++;
b[x]++;
}
cnt+=i*s[i];
if(i*s[i]<ress)return 0;
if(cnt<b[i])return 0;
cnt-=b[i];
add+=s[i]*a[i];
}
if(cnt>0)return 0;
for(int i=1;i<=n;i++)b[i]=0;
cnt=0;
ned=0,has=0;
for(int i=n;i>=1;i--){
int ress=0;
for(auto&x:ed[i]){
if(i==x)ress++;
b[x]++;
}
cnt+=i*s[i];
if(i*s[i]<ress)return 0;
if(cnt<b[i])return 0;
cnt-=b[i];
}
if(cnt>0)return 0;
// for(int i=1;i<=n;i++)printf("%d ",s[i]);
//puts("");
if(add>res)res=add;
return 0;
}
int dfs(int lst,int nows){
if(nows==0){
if(lst==0)work();
return 0;
}
for(int i=0;i*nows<=lst;i++){
s[nows]=i;
dfs(lst-i*nows,nows-1);
}
return 0;
}
int main(){
// freopen("2.in","r",stdin);
scanf("%d",&n);
for(int i=1;i<=n;i++){
int x,y;scanf("%d%d",&x,&y);
ed[x].push_back(y);
bf[y].push_back(x);
}
for(int i=1;i<=n;i++)scanf("%d",a+i);
// puts("!!!");
res=-Inf;
dfs(n,n);
if(res>-Inf)printf("%d\n",res);
else puts("impossible");
// printf("P%d\n",cnt);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3724kb
input:
3 2 3 1 2 2 2 4 5 100
output:
impossible
result:
wrong answer 1st lines differ - expected: '9', found: 'impossible'