QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#114679#5974. Bilingualzwh200830 ✓169ms4492kbC++141.4kb2023-06-22 21:04:292023-06-22 21:04:30

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-22 21:04:30]
  • 评测
  • 测评结果:30
  • 用时:169ms
  • 内存:4492kb
  • [2023-06-22 21:04:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=5005,inf=2e9;
int n,cnt=1,Case,ct,s,t,tot,gap[N],d[N],h[N];
struct edge{int n,t,v;}e[N*50];
map<string,int>mp;
vector<string>a[N];
void add(int x,int y,int z){e[++cnt]={h[x],y,z},h[x]=cnt;}
void Add(int x,int y,int z){add(x,y,z),add(y,x,0);}
int isap(int x,int flow) {
	if(x==t)return flow;
	int res=0;
	for(int i=h[x];i;i=e[i].n) {
		int y=e[i].t;
		if(e[i].v&&d[x]==d[y]+1) {
			int k=isap(y,min(e[i].v,flow-res));
			e[i].v-=k,e[i^1].v+=k,res+=k;
			if(flow==res)return res;
		}
	}
	if(!--gap[d[x]])d[s]=tot;
	return ++gap[++d[x]],res;
}
int maxflow() {
	memset(d,0,sizeof(d)),memset(gap,0,sizeof(gap));
	int res=0;gap[0]=tot;while(d[s]<tot)res+=isap(s,inf);
	return res;
}
void get(vector<string>&g) {
	char ch;string w;g.clear();
	do {
		cin>>w;if(!mp.count(w))mp[w]=++ct;
		g.push_back(w),ch=getchar();
	}while(ch!='\n');
}
void solve() {
	scanf("%d",&n),cnt=1,ct=0,memset(h,0,sizeof(h)),mp.clear();
	for(int i=1;i<=n;i++)get(a[i]);
	if(2*ct+n>5000)while(1);
	s=2*ct+n+1,t=tot=s+1,Add(2*ct+2,t,inf);
	for(auto i:a[1])Add(s,mp[i],inf);
	for(int i=1;i<=n;i++)
		for(auto j:a[i])Add(mp[j]+ct,ct*2+i,inf),Add(ct*2+i,mp[j],inf);
	for(int i=1;i<=ct;i++)Add(i,i+ct,1),Add(i+ct,i,1);
	printf("Case #%d: %d\n",++Case,maxflow());
}
int main() {
	int tt;scanf("%d",&tt);
	while(tt--)solve();
	return 0;
}

详细

Subtask #1:

score: 6
Accepted

Test #1:

score: 6
Accepted
time: 159ms
memory: 4224kb

input:

25
2
he loves to eat baguettes
il aime manger des baguettes
4
a b c d e
f g h i j
a b c i j
f g h d e
4
he drove into a cul de sac
elle a conduit sa voiture
il a conduit dans un cul de sac
il mange pendant que il conduit sa voiture
6
adieu joie de vivre je ne regrette rien
adieu joie de vivre je ne ...

output:

Case #1: 1
Case #2: 4
Case #3: 3
Case #4: 8
Case #5: 979
Case #6: 995
Case #7: 976
Case #8: 994
Case #9: 982
Case #10: 991
Case #11: 982
Case #12: 992
Case #13: 978
Case #14: 990
Case #15: 979
Case #16: 987
Case #17: 978
Case #18: 985
Case #19: 982
Case #20: 988
Case #21: 974
Case #22: 991
Case #23:...

result:

ok 25 lines

Subtask #2:

score: 24
Accepted

Test #2:

score: 24
Accepted
time: 169ms
memory: 4492kb

input:

25
2
he loves to eat baguettes
il aime manger des baguettes
4
a b c d e
f g h i j
a b c i j
f g h d e
4
he drove into a cul de sac
elle a conduit sa voiture
il a conduit dans un cul de sac
il mange pendant que il conduit sa voiture
6
adieu joie de vivre je ne regrette rien
adieu joie de vivre je ne ...

output:

Case #1: 1
Case #2: 4
Case #3: 3
Case #4: 8
Case #5: 761
Case #6: 896
Case #7: 759
Case #8: 915
Case #9: 792
Case #10: 883
Case #11: 719
Case #12: 882
Case #13: 717
Case #14: 844
Case #15: 666
Case #16: 838
Case #17: 705
Case #18: 868
Case #19: 704
Case #20: 899
Case #21: 722
Case #22: 843
Case #23:...

result:

ok 25 lines

Extra Test:

score: 0
Extra Test Passed