답안 #350141

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
350141 2021-01-19T02:50:53 Z arnold518 Ili (COI17_ili) C++14
100 / 100
400 ms 748 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2e4;

int N, M;
char S[MAXN+10];
pii A[MAXN+10];

int B[MAXN+10], C[MAXN+10];

char ans[MAXN+10];

void dfs(int now)
{
	if(now<=N)
	{
		B[now]=0;
		return;
	}
	dfs(A[now].first);
	dfs(A[now].second);
}

void dfs2(int now)
{
	if(now<=N)
	{
		C[now]=0;
		return;
	}
	dfs2(A[now].first);
	dfs2(A[now].second);
}

int main()
{
	scanf("%d%d", &N, &M);
	scanf(" %s", S+N+1);
	for(int i=N+1; i<=N+M; i++)
	{
		char c1, c2;
		int d1, d2;
		scanf(" %c%d %c%d", &c1, &d1, &c2, &d2);
		if(c1=='c') d1+=N;
		if(c2=='c') d2+=N;
		A[i]={d1, d2};
	}

	for(int i=N+1; i<=N+M; i++) ans[i]='?';

	for(int i=1; i<=N; i++) B[i]=1;
	for(int i=N+1; i<=N+M; i++) if(S[i]=='0') dfs(i);
	for(int i=N+1; i<=N+M; i++)
	{
		B[i]=B[A[i].first]|B[A[i].second];
		if(B[i]==0) ans[i]='0';
	}

	for(int i=N+1; i<=N+M; i++)
	{
		if(B[i]==1)
		{
			for(int j=1; j<=N; j++) C[j]=B[j];
			dfs2(i);
			bool flag=true;
			for(int j=N+1; j<=N+M; j++)
			{
				C[j]=C[A[j].first]|C[A[j].second];
				if(S[j]=='1' && C[j]==0) flag=false;
			}
			if(!flag) ans[i]='1';
		}
	}
	printf("%s\n", ans+N+1);
}

Compilation message

ili.cpp: In function 'int main()':
ili.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |  scanf("%d%d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~
ili.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |  scanf(" %s", S+N+1);
      |  ~~~~~^~~~~~~~~~~~~~
ili.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |   scanf(" %c%d %c%d", &c1, &d1, &c2, &d2);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 111 ms 492 KB Output is correct
16 Correct 101 ms 748 KB Output is correct
17 Correct 112 ms 620 KB Output is correct
18 Correct 249 ms 620 KB Output is correct
19 Correct 121 ms 652 KB Output is correct
20 Correct 231 ms 748 KB Output is correct
21 Correct 363 ms 748 KB Output is correct
22 Correct 340 ms 748 KB Output is correct
23 Correct 400 ms 748 KB Output is correct
24 Correct 368 ms 748 KB Output is correct
25 Correct 177 ms 748 KB Output is correct
26 Correct 178 ms 748 KB Output is correct
27 Correct 235 ms 748 KB Output is correct
28 Correct 177 ms 748 KB Output is correct
29 Correct 179 ms 748 KB Output is correct
30 Correct 224 ms 748 KB Output is correct
31 Correct 236 ms 620 KB Output is correct
32 Correct 299 ms 748 KB Output is correct