QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#609709#9412. Stop the Castleucup-team902#AC ✓8ms11308kbC++173.9kb2024-10-04 13:46:052024-10-04 13:46:27

Judging History

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

  • [2024-10-04 13:46:27]
  • 评测
  • 测评结果:AC
  • 用时:8ms
  • 内存:11308kb
  • [2024-10-04 13:46:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define ll long long
#define pii pair<ll,ll>
#define gc getchar
#define fi first
#define se second
#define bg begin

template<typename tp>inline void chemx(tp &a,tp b){(a<b)?(a=b):0;}
template<typename tp>inline void chemn(tp &a,tp b){(a>b)?(a=b):0;}

inline int read(){
	char ch=gc();
	int res=0;bool f=1;
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
	return f?res:-res;
}
cs int N=100005;
int n,m;
int str,des,tot;
struct edge{
	int v,cap,r;
	edge(int a=0,int b=0,int c=0):v(a),cap(b),r(c){}
};
vector<edge> e[N];
inline void addedge(int u,int v,int w){
	e[u].pb(edge(v,w,e[v].size()));
	e[v].pb(edge(u,0,e[u].size()-1));
}
#define It vector<edge>::iterator
namespace Flow{
	int lev[N];It tp[N];
	queue<int> q;
	inline bool bfs(){
		memset(lev,-1,sizeof(int)*(tot+1));
		lev[str]=0,q.push(str);
		while(!q.empty()){
			int u=q.front();q.pop();
			for(edge &x:e[u]){
				if(lev[x.v]==-1&&x.cap>0){
					lev[x.v]=lev[u]+1,q.push(x.v);
				}
			}
		}
		return lev[des]!=-1;
	}
	int dfs(int u,int flow){
		if(u==des)return flow;
		int res=0;
		for(It &it=tp[u];it!=e[u].end();it++){
			if(lev[it->v]==lev[u]+1&&it->cap>0){
				int now=dfs(it->v,min(it->cap,flow-res));
				res+=now,it->cap-=now,e[it->v][it->r].cap+=now;
				if(res==flow)break;
			}
		}
		return res;
	}
	inline int dinic(){
		int res=0;
		while(bfs()){
			for(int i=1;i<=tot;i++)tp[i]=e[i].bg();
			res+=dfs(str,1e9);
		}
		return res;
	}
}
int r[N],c[N],cntx,cnty;
int r2[N],c2[N];
void clear(){
	for(int i=0;i<=tot;i++)e[i].clear();
	str=des=tot=0;
}
struct node{
	int t,l,r;
	node(int _t=0,int _l=0,int _r=0):t(_t),l(_l),r(_r){}
}lix[N],liy[N];
int inter(node x,node y){
	return y.l<=x.t&&x.t<=y.r&&x.l<=y.t&&y.t<=x.r;
}
void solve(){
	n=read();cntx=cnty=0;
	for(int i=1;i<=n;i++)r[i]=read(),c[i]=read();			
	m=read();
	for(int i=1;i<=m;i++)r2[i]=read(),c2[i]=read();
	tot=0,str=++tot,des=++tot;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)if(i!=j&&r[i]==r[j]&&c[i]<c[j]){
		if(c[i]+1==c[j]){
			puts("-1");
			clear();
			return;
		}	
		int ok=0;
		for(int k=1;k<=n;k++)if(r[k]==r[i]&&c[i]<c[k]&&c[k]<c[j]){
			ok=1;
		}
		for(int k=1;k<=m;k++)if(r2[k]==r[i]&&c[i]<c2[k]&&c2[k]<c[j]){
			ok=1;
		}
		if(ok)continue;
		//cout<<i<<" "<<j<<'\n';
	//	cout<<r[i]<<" "<<c[i]+1<<" "<<c[j]-1<<'\n';
		lix[++cntx]=node(r[i],c[i]+1,c[j]-1);
	}
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)if(i!=j&&c[i]==c[j]&&r[i]<r[j]){
		if(r[i]+1==r[j]){
			puts("-1");
			clear();
			return;
		}
		int ok=0;
		for(int k=1;k<=n;k++)if(c[k]==c[i]&&r[i]<r[k]&&r[k]<r[j]){
			ok=1;
		}
		for(int k=1;k<=m;k++)if(c2[k]==c[i]&&r[i]<r2[k]&&r2[k]<r[j]){
			ok=1;
		}
		if(ok)continue;
	//	cout<<c[i]<<" "<<r[i]+1<<" "<<r[j]-1<<'\n';
		liy[++cnty]=node(c[i],r[i]+1,r[j]-1);
	}
	tot=cntx+cnty;
	//cout<<cntx<<" "<<cnty<<'\n';
	str=++tot,des=++tot;
	for(int i=1;i<=cntx;i++)addedge(str,i,1);
	for(int i=1;i<=cnty;i++)addedge(i+cntx,des,1);
	for(int i=1;i<=cntx;i++)
	for(int j=1;j<=cnty;j++)if(inter(lix[i],liy[j])){
		addedge(i,j+cntx,1);
	}
	int res=Flow::dinic();
	cout<<cntx+cnty-res<<'\n';
	
	for(int i=1;i<=cntx;i++){
		int ok=0;
		for(auto x:e[i])if(x.v==str&&x.cap==1){
			ok=1;
		}
		if(ok==0){
			cout<<lix[i].t<<" "<<lix[i].l<<'\n';
		}
	}
	//cout<<"e1\n";
	for(int i=1;i<=cnty;i++){
		int ok=0;
		for(auto x:e[i+cntx])if(x.v==des&&x.cap==0){
			ok=1;
		}
		if(ok==0){
			cout<<liy[i].l<<" "<<liy[i].t<<'\n';
		}
	}
	//cout<<"e2\n";
	for(int i=1;i<=cntx;i++){
		for(auto x:e[i])if(x.v<=cntx+cnty&&x.cap==0){
			cout<<lix[i].t<<" "<<liy[x.v-cntx].t<<'\n';
		}
	}
	clear();
}

int main(){
    #ifdef Stargazer
    freopen("1.in","r",stdin);
    #endif
	int T=read();
	while(T--){
		solve();
	}
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 10932kb

input:

4
7
1 3
6 6
4 7
2 1
6 3
4 1
2 6
3
3 4
6 4
3 1
2
1 1
2 2
0
3
1 1
1 3
3 3
1
1 2
3
1 1
1 3
2 3
0

output:

2
2 3
4 6
0
1
2 3
-1

result:

ok ok 4 cases (4 test cases)

Test #2:

score: 0
Accepted
time: 0ms
memory: 11284kb

input:

21
11
3 5
18 6
19 12
27 48
28 38
30 12
33 18
42 18
43 38
45 46
48 34
3
2 6
24 4
41 45
15
11 6
15 27
16 9
16 14
16 48
19 26
25 12
27 26
28 4
31 40
32 6
33 50
37 50
46 11
50 29
17
1 49
4 9
9 15
9 22
11 31
11 46
14 28
17 5
17 49
18 43
20 31
30 46
33 11
33 33
34 15
36 6
47 10
2
16 46
36 30
11
7 34
7 41
...

output:

3
20 12
29 38
34 18
5
16 10
16 15
12 6
20 26
34 50
0
1
16 10
0
1
43 22
5
1 3
1 13
33 10
44 45
42 44
0
5
27 41
29 26
44 4
8 1
21 15
1
32 9
0
0
0
0
6
12 11
23 44
29 21
24 46
23 10
35 34
0
3
20 30
43 25
31 17
0
-1
3
25 7
17 39
16 36
6
6 4
7 3
3 10
2 11
5 5
8 9

result:

ok ok 21 cases (21 test cases)

Test #3:

score: 0
Accepted
time: 0ms
memory: 11264kb

input:

2
200
7 52
9 160
10 4
12 61
18 436
19 430
20 499
24 139
25 416
29 53
33 153
35 275
35 310
37 25
38 477
39 349
42 120
44 158
45 330
49 486
50 204
51 67
52 138
52 305
56 139
63 132
66 4
67 327
70 484
71 67
72 308
74 218
76 479
81 139
82 90
86 201
87 335
91 35
91 220
92 496
94 29
94 436
96 359
97 299
1...

output:

46
35 276
187 433
224 393
260 223
261 468
274 67
277 189
311 455
390 308
440 179
453 251
11 4
19 436
21 499
38 25
39 477
52 67
57 139
138 429
240 35
271 186
278 272
286 367
307 367
380 385
415 305
52 139
91 61
94 153
126 138
126 275
132 67
154 160
154 496
185 147
187 467
199 432
224 35
270 356
277 3...

result:

ok ok 2 cases (2 test cases)

Test #4:

score: 0
Accepted
time: 0ms
memory: 11220kb

input:

20
13
89287395 441913071
89287395 590314987
142917372 582720391
142917372 598813561
232930851 582720391
263974835 468188689
263974835 490702144
543529670 152471388
543529670 219371706
647691663 598813561
772865038 598813561
773363571 482933265
773363571 561453301
8
128947560 120560639
264980960 4742...

output:

8
89287395 441913072
142917372 582720392
263974835 468188690
543529670 152471389
773363571 482933266
142917373 582720391
142917373 598813561
647691664 598813561
7
808969359 386523246
808969359 891229782
59832704 871951216
92745430 358274214
469117951 762966373
808969360 354711322
808969359 818037531...

result:

ok ok 20 cases (20 test cases)

Test #5:

score: 0
Accepted
time: 0ms
memory: 11308kb

input:

2
184
35763790 435860426
152681166 443483111
261932524 745277126
261932524 787982418
314305867 342102981
314305867 522593781
314305867 747023891
314305867 811404535
314305867 816914009
314305867 857896659
319901983 797458033
321347896 342102981
332550928 902179526
343207116 914408792
350635050 15515...

output:

160
261932524 745277127
314305867 522593782
314305867 811404536
314305867 816914010
350635050 155155062
350635050 342102982
350635050 837963934
469496529 461654556
469496529 842430756
469496529 857896660
471526868 438907615
496813081 725569500
496813081 732085441
496813081 751818165
496813081 902179...

result:

ok ok 2 cases (2 test cases)

Test #6:

score: 0
Accepted
time: 0ms
memory: 11308kb

input:

2
193
78368109 329329995
87932514 657474465
87932514 903492853
94608574 845872655
103602204 88649154
124431127 405860533
145262472 108198774
145262472 907127202
154400439 136367504
165270984 773451933
184157521 409828915
197728547 291882089
197728547 609623645
211750768 843867422
246178069 108396139...

output:

145
87932514 657474466
365329221 29599938
365329221 62966786
365329221 88649155
365329221 141752548
365329221 211732514
365329221 233466163
365329221 288981804
365329221 344833278
365329221 368389626
365329221 394163430
365329221 394743043
365329221 443101075
365329221 480642953
365329221 502303729
...

result:

ok ok 2 cases (2 test cases)

Test #7:

score: 0
Accepted
time: 0ms
memory: 11024kb

input:

2
192
1075648 579875717
1075648 937648715
1393060 191616432
3957616 541362608
3957616 971879257
5415801 541362608
5887448 541362608
5887448 624842533
25767120 610618164
26193206 214214028
26193206 231445627
26727662 374314271
29550509 755417826
29550509 917592925
30033126 610618164
31134588 58188305...

output:

131
1075648 579875718
3957616 541362609
5887448 541362609
26193206 214214029
29550509 755417827
133595743 231445628
223207847 394672551
223207847 541362609
235369723 307977478
235369723 541362609
333807226 755417827
429088204 401547042
439147697 426561707
439147697 541362609
439147697 699217245
5097...

result:

ok ok 2 cases (2 test cases)

Test #8:

score: 0
Accepted
time: 0ms
memory: 11000kb

input:

20
14
378192988 147499872
378192988 837331700
449924898 147499872
449924898 837331700
592684636 147499872
592684636 837331700
783332532 147499872
783332532 837331700
378192988 197547597
783332532 197547597
378192988 343857831
783332532 343857831
378192988 576579017
783332532 576579017
2
449924898 19...

output:

15
378192988 147499873
783332532 147499873
378192988 197547598
783332532 197547598
378192988 343857832
783332532 343857832
378192988 576579018
783332532 576579018
378192989 147499872
378192989 837331700
449924899 147499872
449924899 837331700
592684637 147499872
592684637 837331700
378192989 5765790...

result:

ok ok 20 cases (20 test cases)

Test #9:

score: 0
Accepted
time: 0ms
memory: 11144kb

input:

2
200
8623893 3649468
8623893 989134714
24820918 3649468
24820918 989134714
43705451 3649468
43705451 989134714
45500146 3649468
45500146 989134714
58265855 3649468
58265855 989134714
112263159 3649468
112263159 989134714
126496650 3649468
126496650 989134714
137574156 3649468
137574156 989134714
14...

output:

249
8623893 3649469
956639323 3649469
8623893 6255308
956639323 6255308
8623893 11610915
956639323 11610915
8623893 23366505
956639323 23366505
8623893 28938722
956639323 28938722
8623893 31914493
956639323 31914493
8623893 36029446
956639323 36029446
8623893 66226936
956639323 66226936
8623893 8415...

result:

ok ok 2 cases (2 test cases)

Test #10:

score: 0
Accepted
time: 0ms
memory: 11308kb

input:

2
200
2691939 27674656
2691939 984614319
30225807 27674656
30225807 984614319
39388076 27674656
39388076 984614319
55883389 27674656
55883389 984614319
77258752 27674656
77258752 984614319
106874917 27674656
106874917 984614319
144383292 27674656
144383292 984614319
145360776 27674656
145360776 9846...

output:

216
2691939 27674657
997421612 27674657
2691939 69029841
997421612 69029841
2691939 160188719
997421612 160188719
2691939 176264535
997421612 176264535
2691939 189367595
997421612 189367595
2691939 206375959
997421612 206375959
2691939 234369847
997421612 234369847
2691939 243902653
997421612 243902...

result:

ok ok 2 cases (2 test cases)

Test #11:

score: 0
Accepted
time: 8ms
memory: 11016kb

input:

2
200
1005937 7
3412691 7
5764908 7
7897785 7
8061992 7
12801501 7
18529696 7
22574605 7
25203351 7
34574958 7
34998216 7
40928451 7
49792193 7
55962320 7
59632864 7
62353373 7
62611196 7
65346591 7
71459320 7
71550121 7
72215989 7
82584263 7
86119549 7
96204862 7
96940713 7
97693112 7
102067050 7
1...

output:

199
1005938 7
3412692 7
5764909 7
7897786 7
8061993 7
12801502 7
18529697 7
22574606 7
25203352 7
34574959 7
34998217 7
40928452 7
49792194 7
55962321 7
59632865 7
62353374 7
62611197 7
65346592 7
71459321 7
71550122 7
72215990 7
82584264 7
86119550 7
96204863 7
96940714 7
97693113 7
102067051 7
105...

result:

ok ok 2 cases (2 test cases)

Extra Test:

score: 0
Extra Test Passed