QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#423115 | #6406. Stage Clear | xlwang | WA | 0ms | 3884kb | C++14 | 3.8kb | 2024-05-27 21:10:09 | 2024-05-27 21:10:10 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define fr(i,j,k) for(register int i=j;i<=k;++i)
#define rf(i,j,k) for(register int i=j;i>=k;--i)
#define foredge(i,j) for(register int i=head[j];i;i=e[i].nxt)
#define pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
#define pii pair<int,int>
#define mk make_pair
using namespace std;
inline int read(){
int x=0;
bool f=0;
char c=getchar();
while(!isdigit(c)) f|=(c=='-'),c=getchar();
while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
return f?-x:x;
}
inline void write(int x){
if(x<0){putchar('-');x=-x;}
if(x>9)write(x/10);
putchar(x%10+'0');
}
inline void writeln(int x){write(x); puts("");}
inline void writepl(int x){write(x); putchar(' ');}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int randfind(int l,int r){return rnd()%(r-l+1)+l;}
//inline void init(){
// int t=read();
// while(t--) work();
//}
int n,m;
inline void init(){
n=read();m=read();
}
namespace sub1{
const int Maxn=70,Maxs=(1<<26)+10;
const ll inf=1e18;
ll f[Maxs];
int ed[Maxn];
ll a[Maxn],b[Maxn];
inline void chkmin(ll &x,ll y){if(x>y) x=y;}
inline void work(){
fr(i,2,n) scanf("%lld%lld",&a[i],&b[i]);
fr(i,1,m){int x,y;x=read();y=read();ed[y]|=(1<<(x-1));}
int S=(1<<(n-1))-1;
fr(i,1,S) f[i]=inf;
fr(i,0,S){
int tr=i*2+1;
ll now=0;
fr(id,2,n) if(i&(1<<(id-2))) now+=b[id]-a[id];
fr(id,2,n) if(ed[id]&tr && !(i&(1<<(id-2)))) chkmin(f[i+(1<<(id-2))],max(f[i],a[id]-now));
}
printf("%lld\n",f[S]);
}
}
namespace sub2{
const int Maxn=70;
vector<int> pre[Maxn];
int father[Maxn],fa[Maxn];
inline int getfa(int x){
if(fa[x]==x) return x;
return fa[x]=getfa(fa[x]);
}
inline void merge(int x,int y){fa[getfa(x)]=getfa(y);}
struct node{
int id;
ll minn,now;
};
bool operator < (node A,node B){
int flag;flag=(A.now>0)+(B.now>0);
if(flag==1) return A.now<0;
if(flag==2) return A.minn>B.minn;
return A.now<B.now;
}
const ll inf=1e18;
ll ans=inf;
ll a[Maxn],b[Maxn];
ll nowa[Maxn],nowb[Maxn];
inline void check(){
priority_queue<node> q;
fr(i,1,n) fa[i]=i;
fr(i,2,n) merge(i,father[i]);
fr(i,2,n) if(getfa(i)!=getfa(1)) return;
fr(i,1,n) fa[i]=i;
nowa[1]=nowb[1]=0;
fr(i,2,n) nowa[i]=a[i],nowb[i]=b[i];
fr(i,2,n) q.push((node){i,a[i],b[i]});
// fr(i,2,n) cout<<i<<' '<<father[i]<<endl;
while(!q.empty()){
// cerr<<"**"<<endl;
node tmp;tmp=q.top();q.pop();
if(tmp.id==1) continue;
if(getfa(tmp.id)!=tmp.id || nowa[tmp.id]!=tmp.minn || nowb[tmp.id]!=tmp.now) continue;
int Fa;Fa=getfa(father[tmp.id]);
nowa[Fa]=max(nowa[Fa],nowa[tmp.id]-nowb[Fa]);
nowb[Fa]+=nowb[tmp.id];merge(tmp.id,Fa);
q.push((node){Fa,nowa[Fa],nowb[Fa]});
}
// fr(i,1,n) cout<<nowa[i]<<' '<<nowb[i]<<endl;
// cout<<nowa[1]<<endl;
ans=min(ans,nowa[1]);
}
inline void dfs(int x){
if(x==(n+1)){check();return;}
for(auto y:pre[x]){father[x]=y;dfs(x+1);}
}
inline void work(){
fr(i,2,n) scanf("%lld%lld",&a[i],&b[i]);
fr(i,1,m){int x,y;x=read();y=read();pre[y].pb(x);}
dfs(2);
printf("%lld\n",ans);
}
}
inline void work(){
if(n<=0) sub1::work();
else sub2::work();
}
signed main(){
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
init();work();
// printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3868kb
input:
4 4 4 2 5 3 2 6 1 2 1 3 2 4 3 4
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3884kb
input:
15 14 254040392438309 117083115436273 500005748229691 557255157630172 821034233718230 865199673774998 659892147898798 987564141425694 81172575487567 811635577877255 751768357864605 341103322647288 454926350150218 140191090713900 921608121471585 659295670987251 223751724062143 505619245326640 8907765...
output:
367841861670175
result:
wrong answer 1st numbers differ - expected: '1665396301509143', found: '367841861670175'