답안 #289112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
289112 2020-09-02T11:15:13 Z TadijaSebez Friends (BOI17_friends) C++11
69 / 100
1000 ms 11000 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=2550;
vector<int> E[N],cmp[N];
stack<int> cns;
bool in[N],in_stk[N],done[N];
int p,q,a,b;
void cl(){for(int i=0;i<N;i++)in[i]=in_stk[i]=done[i]=0;a=b=0;cns=stack<int>();}
bool BCK(int idx){
	if(a>p||b>q||a+b+cns.size()>p+q)return 0;
	if(cns.empty())return 1;
	int u=cns.top();cns.pop();
	a++;in[u]=1;in_stk[u]=0;done[u]=1;
	int cnt=0;
	for(int v:E[u]){
		if(done[v]&&!in[v])b++;
		if(!done[v]&&!in_stk[v]){
			cns.push(v);
			in_stk[v]=1;
			cnt++;
		}
	}
	if(BCK(idx)){
		cmp[idx].pb(u);
		return 1;
	}
	a--;
	in[u]=0;
	for(int v:E[u])if(done[v]&&!in[v])b--;
	while(cnt--)in_stk[cns.top()]=0,cns.pop();
	for(int v:E[u])if(in[v])b++;
	if(BCK(idx)){
		return 1;
	}
	for(int v:E[u])if(in[v])b--;
	done[u]=0;
	in_stk[u]=1;
	cns.push(u);
	return 0;
}
void Fix(int A,int B){
	set<int> F,S,same;
	for(int i:cmp[A])F.insert(i);
	for(int i:cmp[B]){
		S.insert(i);
		if(F.count(i))same.insert(i),F.erase(i);
	}
	int cnt=0;
	for(int i:F)
		for(int j:E[i])
			if(!F.count(j))
				cnt++;
	if(cnt>q){
		for(int i:same)F.insert(i),S.erase(i);
	}
	cmp[A].clear();for(int i:F)cmp[A].pb(i);
	cmp[B].clear();for(int i:S)cmp[B].pb(i);
}
int con[N][N];
int main(){
	int n;
	scanf("%i %i %i",&n,&p,&q);
	for(int i=1;i<=n;i++){
		int m;scanf("%i",&m);
		while(m--){
			int j;scanf("%i",&j);j++;
			con[i][j]=1;
			E[i].pb(j);
		}
	}
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)if(con[i][j]+con[j][i]==1)return 0*printf("detention\n");
	for(int i=1;i<=n;i++){
		cl();
		in[i]=done[i]=1;a++;
		for(int j:E[i]){
			cns.push(j);
			in_stk[j]=1;
		}
		if(!BCK(i))return 0*printf("detention\n");
		cmp[i].pb(i);
		sort(cmp[i].begin(),cmp[i].end());
	}
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)Fix(i,j);
	int cnt=0;
	for(int i=1;i<=n;i++)if(cmp[i].size())cnt++;
	printf("home\n");
	printf("%i\n",cnt);
	for(int i=1;i<=n;i++)if(cmp[i].size()){
		printf("%i ",cmp[i].size());
		for(int j:cmp[i])printf("%i ",j-1);
		printf("\n");
	}
	return 0;
}

Compilation message

friends.cpp: In function 'bool BCK(int)':
friends.cpp:11:29: warning: comparison of integer expressions of different signedness: 'std::stack<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   11 |  if(a>p||b>q||a+b+cns.size()>p+q)return 0;
      |               ~~~~~~~~~~~~~~^~~~
friends.cpp: In function 'int main()':
friends.cpp:90:12: warning: format '%i' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   90 |   printf("%i ",cmp[i].size());
      |           ~^   ~~~~~~~~~~~~~
      |            |              |
      |            int            std::vector<int>::size_type {aka long unsigned int}
      |           %li
friends.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   63 |  scanf("%i %i %i",&n,&p,&q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~
friends.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   65 |   int m;scanf("%i",&m);
      |         ~~~~~^~~~~~~~~
friends.cpp:67:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   67 |    int j;scanf("%i",&j);j++;
      |          ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 14 ms 1280 KB Output is correct
3 Correct 7 ms 1024 KB Output is correct
4 Correct 2 ms 1536 KB Output is correct
5 Correct 2 ms 1536 KB Output is correct
6 Correct 1 ms 1408 KB Output is correct
7 Correct 3 ms 896 KB Output is correct
8 Correct 25 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 14 ms 1280 KB Output is correct
3 Correct 7 ms 1024 KB Output is correct
4 Correct 2 ms 1536 KB Output is correct
5 Correct 2 ms 1536 KB Output is correct
6 Correct 1 ms 1408 KB Output is correct
7 Correct 3 ms 896 KB Output is correct
8 Correct 25 ms 1536 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 388 ms 4736 KB Output is correct
11 Correct 441 ms 5632 KB Output is correct
12 Correct 490 ms 5624 KB Output is correct
13 Correct 530 ms 5888 KB Output is correct
14 Correct 14 ms 7808 KB Output is correct
15 Correct 19 ms 7808 KB Output is correct
16 Correct 8 ms 8576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 14 ms 1280 KB Output is correct
11 Correct 7 ms 1024 KB Output is correct
12 Correct 2 ms 1536 KB Output is correct
13 Correct 2 ms 1536 KB Output is correct
14 Correct 1 ms 1408 KB Output is correct
15 Correct 3 ms 896 KB Output is correct
16 Correct 25 ms 1536 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 388 ms 4736 KB Output is correct
19 Correct 441 ms 5632 KB Output is correct
20 Correct 490 ms 5624 KB Output is correct
21 Correct 530 ms 5888 KB Output is correct
22 Correct 14 ms 7808 KB Output is correct
23 Correct 19 ms 7808 KB Output is correct
24 Correct 8 ms 8576 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 815 ms 8444 KB Output is correct
27 Correct 627 ms 8056 KB Output is correct
28 Correct 605 ms 7404 KB Output is correct
29 Correct 10 ms 4864 KB Output is correct
30 Correct 15 ms 5888 KB Output is correct
31 Correct 8 ms 5888 KB Output is correct
32 Correct 8 ms 8808 KB Output is correct
33 Execution timed out 1088 ms 11000 KB Time limit exceeded
34 Halted 0 ms 0 KB -