QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#423110#6406. Stage ClearxlwangWA 1124ms71072kbC++143.8kb2024-05-27 21:08:492024-05-27 21:08:50

Judging History

This is the latest submission verdict.

  • [2024-08-15 21:05:17]
  • hack成功,自动添加数据
  • (/hack/778)
  • [2024-05-27 21:08:50]
  • Judged
  • Verdict: WA
  • Time: 1124ms
  • Memory: 71072kb
  • [2024-05-27 21:08:49]
  • Submitted

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<=26) 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;
}

詳細信息

Test #1:

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

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: 0
Accepted
time: 2ms
memory: 4204kb

input:

15 14
254040392438309 117083115436273
500005748229691 557255157630172
821034233718230 865199673774998
659892147898798 987564141425694
81172575487567 811635577877255
751768357864605 341103322647288
454926350150218 140191090713900
921608121471585 659295670987251
223751724062143 505619245326640
8907765...

output:

1665396301509143

result:

ok 1 number(s): "1665396301509143"

Test #3:

score: 0
Accepted
time: 16ms
memory: 4836kb

input:

18 17
636830992776530 847574431876821
330869946457865 78274534165482
450581372553540 11565219334965
8736347226844 17186323694285
870805093198860 559070167736042
674369178493171 930151818400874
641605209598997 222521062460239
450936030349531 469197172169023
831295459816974 626096008793091
53095460351...

output:

2375957544280218

result:

ok 1 number(s): "2375957544280218"

Test #4:

score: 0
Accepted
time: 63ms
memory: 8416kb

input:

20 19
539893468691183 767805205447882
240338186903141 960937349402327
942645580569365 896509929612645
542601575005817 191461109090531
540992546866047 765080044816119
904535155855114 858111921213175
452499200048240 115895143306864
983856946412026 838504718536099
586421298181479 265212699386882
677124...

output:

800919806038419

result:

ok 1 number(s): "800919806038419"

Test #5:

score: 0
Accepted
time: 1124ms
memory: 71072kb

input:

24 23
114281007218527 308690671179962
145951034437731 718976086594208
709172151907814 926071954787084
224496444610281 498657753059525
874422017133378 857676356343078
532175866197017 818525693672607
303837639402605 374469705563954
512244364294540 952911486867703
748959419417502 249992707230361
512696...

output:

114281007218527

result:

ok 1 number(s): "114281007218527"

Test #6:

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

input:

36 35
389328367777319 678636570542258
32216944647452 612585362150577
891592845704885 596030605892036
688825276167602 461516360471825
916552899998310 106733202183953
400050408958777 670724326933521
995792861502757 894514508573875
14511185222713 612305257166443
175168368096281 508263855969282
85578802...

output:

152099300681994

result:

wrong answer 1st numbers differ - expected: '171942144116875', found: '152099300681994'