QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#687989 | #8936. Team Arrangement | wyxqwq | WA | 0ms | 3708kb | C++14 | 2.5kb | 2024-10-29 22:24:49 | 2024-10-29 22:24:51 |
Judging History
answer
#include<bits/stdc++.h>
#define vectorwyx maze
namespace vectorwyx{
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define sml(x,y) (x=min(x,y))
#define big(x,y) (x=max(x,y))
#define ll long long
#define uint unsigned
#define ull unsigned long long
#define umap unordered_map
#define db double
#define fo(i,x,y) for(int i=(x);i<=(y);++i)
#define go(i,x,y) for(int i=(x);i>=(y);--i)
#define ptc putchar
#define gtc getchar
#define emp emplace
#define re return
#define co continue
#define brk break
#define HH (ptc('\n'))
#define bctz __builtin_ctzll
#define bclz __builtin_clz
#define bppc __builtin_popcount
using namespace std;
ll seed=chrono::system_clock::now().time_since_epoch().count();
mt19937 rnd(seed);
inline int rm(int x,int y){return (int)(rnd()%(y-x+1ll)+x);}
inline int read(){signed ch=getchar();int x=0,f=1;while(!isdigit(ch)){if(ch==(int)('-'))f=-1;ch=getchar();}while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
template<typename T> void out(T *a,int l,int r){fo(i,l,r) cout<<*(a+i)<<' ';puts("");}
const int N=100,inf=1e9;
namespace Heap{
int c[N];
ull sts;
void clear(){memset(c,0,sizeof c);sts=0;}
void push(int x){
// printf("push(%d)\n",x);
if(!c[x]) sts|=1ll<<x;
c[x]++;
}
int top(){re __builtin_ctzll(sts);}
bool pop(int k){
// printf("pop(%d)\n",k);
while(k){
if(!sts) re 0;
int x=top();
if(c[x]>k){c[x]-=k;re 1;}
k-=c[x],c[x]=0;
sts^=1<<x;
}
re 1;
}
}
int l[N],r[N],w[N],n,c[N],ans=-inf;
vector<int> g[N];
void play(){
Heap::clear();
// cout<<"play:";out(c,1,n);
fo(i,1,n){
for(int j:g[i]) Heap::push(j);
if(!Heap::pop(c[i]*i)) re;
if(Heap::top()<=i) re;
}
int val=0;
fo(i,1,n) val+=w[i]*c[i];
big(ans,val);
}
void dfs(int id,int res){
// printf("dfs(%d,%d)\n",id,res);
if(res==0){play();re;}
if(res<id) re;
if(id>n) re;
dfs(id+1,res);
fo(i,1,res/id){
res-=id;
c[id]=i;
dfs(id+1,res);
}
c[id]=0;
}
signed main(){
cin>>n;
fo(i,1,n) l[i]=read(),r[i]=read(),g[l[i]].pb(r[i]);
fo(i,1,n) w[i]=read();
dfs(1,n);
if(ans==-inf) cout<<"impossible";
else cout<<ans;
return 0;
}
}
/*
3
2 3
1 2
2 2
4 5 100
-------------------------------------------------
*/
signed main(){re vectorwyx::main();}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3696kb
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: 3632kb
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: 3708kb
input:
2 1 1 2 2 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3560kb
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: 3708kb
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
Wrong Answer
time: 0ms
memory: 3692kb
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:
-83715961
result:
wrong answer 1st lines differ - expected: '-16558567', found: '-83715961'