QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#666601 | #8936. Team Arrangement | lytqwq | WA | 0ms | 3936kb | C++14 | 1.7kb | 2024-10-22 19:16:35 | 2024-10-22 19:16:46 |
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:bf[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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3796kb
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: 3876kb
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: 3804kb
input:
2 1 1 2 2 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3840kb
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: 3936kb
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: 0
Accepted
time: 0ms
memory: 3796kb
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
output:
-16558567
result:
ok single line: '-16558567'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
14 1 2 1 4 2 3 3 5 4 5 2 5 2 4 2 4 1 2 3 4 1 5 2 4 1 1 4 5 -13763 -7354207 1096407 -9063321 -4824546 -6275546 1258145 -5272834 -8631107 3581157 2320771 -7714508 8446625 -6816167
output:
-2673021
result:
ok single line: '-2673021'
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 3808kb
input:
14 2 3 4 4 1 7 3 6 3 4 1 1 1 4 4 7 3 7 1 7 2 3 6 6 1 1 3 6 2923142 1686477 640352 2848353 9202543 -4441381 4866381 -3610520 8124124 -1372894 1111310 -7538627 466143 9937961
output:
10099540
result:
wrong answer 1st lines differ - expected: '5939733', found: '10099540'