QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#83481#3249. 分组作业fengyuyueAC ✓32ms5500kbC++144.5kb2023-03-02 09:44:202023-03-02 09:44:22

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-02 09:44:22]
  • 评测
  • 测评结果:AC
  • 用时:32ms
  • 内存:5500kb
  • [2023-03-02 09:44:20]
  • 提交

answer

#include<bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define gc getchar
#define pc putchar
#define pii pair<int,int>
#define pil pair<int,long long>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define For(i,l,r) for(int i=(l);i<=(r);i++)
#define IFor(i,r,l) for(int i=(r);i>=(l);i--)
#define for_son(u) for(int e=head[u];e;e=nxt[e])
#define eps (1e-8)
#define ll_INF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f

using namespace std;

char aa;

namespace ljh
{

namespace IO
{
//    const int SIZ=1<<20;
//    char ibuf[SIZ],*p1,*p2,obuf[SIZ],*p3=obuf;
//  #define gc() (p1==p2&&(p2=(p1=ibuf)+fread(ibuf,1,SIZ,stdin),p1==p2)?EOF:*p1++)
//  void pc(const char &c)
//  {
//      if(p3-obuf==SIZ) fwrite(obuf,1,SIZ,stdout),p3=obuf;
//      *p3++=c;
//  }
    int rd()
    {
        int x=0,f=1;
        char ch=gc();
        while(!isdigit(ch)){
            if(ch=='-') f=-1;
            ch=gc();
        }
        while(isdigit(ch)){
            x=x*10+ch-'0';
            ch=gc();
        }
        return x*f;
    }
    void wr(int x,char ch)
    {
        if(x<0) x=-x,pc('-');
        static char st[12];
        int top=0;
        do{
            st[top++]=x%10+'0',x/=10;
        }while(x);
        while(top) pc(st[--top]);
        pc(ch);
    }
    ll ll_rd()
    {
        ll x=0;
        int f=1;
        char ch=gc();
        while(!isdigit(ch)){
            if(ch=='-') f=-1;
            ch=gc();
        }
        while(isdigit(ch)){
            x=x*10+ch-'0';
            ch=gc();
        }
        return x*f;
    }
    void ll_wr(ll x,char ch)
    {
        if(x<0) x=-x,pc('-');
        static char st[22];
        int top=0;
        do{
            st[top++]=x%10+'0',x/=10;
        }while(x);
        while(top) pc(st[--top]);
        pc(ch);
    }
}

using namespace IO;

const int N=5005,M=1e4+5,V=N*3,E=N*7+M*2,mod=0;

namespace tem
{
//  void add_edge(int u,int v){nxt[++cnt]=head[u],to[cnt]=v,head[u]=cnt;}
    int qpow(int a,int b,int p)
    {
        a%=p;
        int res=1;
        while(b){
            if(b&1) res=1ll*res*a%p;
            a=1ll*a*a%p;
            b>>=1;
        }
        return res;
    }
    int get_inv(int x){return qpow(x,mod-2,mod);}
    int lowbit(int x){return x&(-x);}
    void add(int &x,const int y){ x=(x+y>=mod?x+y-mod:x+y); }
//  int get(int x) {return fa[x]==x?x:fa[x]=get(fa[x])};
    int gcd(int a,int b){return b?gcd(b,a%b):a;}
    int lcm(int a,int b){return a/gcd(a,b)*b;}
}

using namespace tem;

int n,m,c[N<<1],d[N<<1],e[N<<1];

int s,t;
int cnt=1,head[V],nxt[E<<1],to[E<<1];
ll vol[E<<1];
int now[V],dis[V];

void add_edge(int u,int v,ll d)
{
	nxt[++cnt]=head[u];
	to[cnt]=v;
	vol[cnt]=d;
	head[u]=cnt;
}

void add_flow(int u,int v,ll d)
{
	add_edge(u,v,d),add_edge(v,u,0);
}

bool bfs()
{
	memset(dis,0,sizeof(dis));
	queue<int>q;
	dis[s]=1;
	now[s]=head[s];
	q.push(s);
	bool flag=false;
	while(!q.empty()){
		int u=q.front();
		q.pop();
		for_son(u){
			int v=to[e];
			if(!dis[v]&&vol[e]){
				dis[v]=dis[u]+1;
				now[v]=head[v];
				q.push(v);
				if(v==t) flag=true;
			}
		}
	}
	return flag;
}

ll dinic(int u,ll flw)
{
	if(u==t) return flw;
	ll rst=flw;
	for(int e=now[u];e;e=now[u]=nxt[e]){
		int v=to[e];
		if(dis[v]==dis[u]+1&&vol[e]){
			ll k=dinic(v,min(vol[e],rst));
			if(!k) dis[v]=0;
			vol[e]-=k;
			vol[e^1]+=k;
			rst-=k;
		}
		if(!rst) break;
	}
	return flw-rst;
}

ll mxflow()
{
	ll res=0,flw=0;
	while(bfs()) while(flw=dinic(s,ll_INF)) res+=flw;
	return res;
}

void solve()
{
	n=rd(),m=rd();
	For(i,1,n*2) c[i]=rd(),d[i]=rd(),e[i]=rd();
	s=n*3+1,t=s+1;
	ll dt=1ll*(n*7+m*3)*INF;
	For(i,1,n*2){
		int j=(i&1)?i+1:i-1;
		add_flow(s,i,d[i]+dt),add_flow(i,j,e[i]),add_flow(i,n*2+(i+1)/2,c[i]+dt);
	}
	For(i,1,n) add_flow(n*2+i,t,c[i*2-1]+c[i*2]+dt*2);
	while(m--){
		int A=rd(),B=rd(),a=rd(),b=rd();
		add_flow(B,n*2+(A+1)/2,a),add_flow(n*2+(B+1)/2,A,b);
	}
	ll_wr(mxflow()-dt*n*2,'\n');
}

void main()
{
    int T=1;
    while(T--) solve();
}

/*
*/

}

char bb;

signed main()
{
//  freopen("1.in","r",stdin);
//  freopen("1.out","w",stdout);
//  int st=clock();
    ljh::main();
//  int ed=clock();
//  cerr<<ed-st<<"ms"<<endl;
//      cerr<<(&bb-&aa)/1024/1024<<"MB"<<endl;
//  fclose(stdin);
//  fclose(stdout);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 32ms
memory: 5416kb

input:

5000 10000
23060775 12 2
255978380 28 517
5 6624 26
151149 45131806 23849036
489 484971 24970
162846 1993316 188305
56311199 2003 211
1 50534913 517527
364913 882765 298
71 26 122914059
13 65459 18150033
20 607 8
380059068 3873712 228
9813 5449 6370
3309369 37410691 8
181 1 62340851
1705 4 107
8 209...

output:

22929674417

result:

ok single line: '22929674417'

Test #2:

score: 0
Accepted
time: 31ms
memory: 5412kb

input:

5000 10000
10055 16 122
4784525 16 23548777
75 3 412576
26487664 16119952 1092
3168 28 16059
33 4 13
2 1319671 7150391
17548 31559813 3201
6910 499901569 2
86633 8794940 2
4 2 85
1749 9908314 45526
10 631569 2347
18 141185 145333
23 27 117121
3825480 32645 5236
3 32022 1298
8 51750221 233
4 16102047...

output:

21306827991

result:

ok single line: '21306827991'

Test #3:

score: 0
Accepted
time: 27ms
memory: 5360kb

input:

5000 10000
48362 83079 12461784
16 4689773 2
763 3650 1128
2118 75447925 253189
47745409 622140 70841
302 162849091 1258
3399198 91 808632
16168406 10380 2
370511 10 3193109
261594 4 2
128 106331221 2
605 28343 601
19 1224480 37551173
49 78375152 493909
110536 1 836
28790 8 133
8 40 4
533035 879 391...

output:

22066314160

result:

ok single line: '22066314160'

Test #4:

score: 0
Accepted
time: 29ms
memory: 5452kb

input:

5000 10000
5564 607330 2584640
126520704 169669 3
231555 402303 114
2 128 58
290016 13 74249
8126414 279 974
1304 119651095 35466664
992290 3414 63
23564 1091 18168
418 125135735 3
29 1295683 424396930
1993 12647005 20
7 712237 1086773
500004515 6 355786
383393 486213 73
21141 29726 665
1 59959 2020...

output:

22438919820

result:

ok single line: '22438919820'

Test #5:

score: 0
Accepted
time: 23ms
memory: 5488kb

input:

5000 10000
23 1 217
41 249931 61567
3096055 3 7
24 12529 1
246322439 144141318 223606
39 906 2
22654307 3963932 3447414
7949665 51935780 344666
30 5058423 2825
148134 7532713 1140
242 5560395 4264
62940 8262918 182
7825 9865191 2992
138038614 24828018 33318812
11 1 4741355
241 533 3
4337359 741573 3...

output:

21645286114

result:

ok single line: '21645286114'

Test #6:

score: 0
Accepted
time: 21ms
memory: 5500kb

input:

5000 10000
53751618 18 124436
857 472 16
13506752 72 6929805
1313173 1 8
13 3 9428917
114702 15875684 375277
95772377 1 19
46 146 544774
2606 90182736 313
2 26253 330
92 17290550 229451029
53 3175 2
48316557 38441802 31
52027 40844521 966
2 455 40909310
6556 6662246 17592087
4914675 39 11812
4590536...

output:

24730200863

result:

ok single line: '24730200863'

Test #7:

score: 0
Accepted
time: 25ms
memory: 5360kb

input:

5000 10000
529152667 2028658 288974
46 2 1853274
212853 4442959 1
7439830 113977860 15476191
87430 6 972573
112375 4489 485
1273959 4049 4059
21 39694709 5
15511 256587916 2
164834468 4 95557537
9330 3 31231
1880144 197069 5753237
102274889 2187511 108044
1906 76869460 12
30311 27016904 6492296
1645...

output:

21376330041

result:

ok single line: '21376330041'

Test #8:

score: 0
Accepted
time: 2ms
memory: 3436kb

input:

3 2
1 1 999
1 1 999
1 999 999
1 999 999
999 1 999
999 1 999
5 1 999 1
1 3 100 1

output:

106

result:

ok single line: '106'