답안 #393096

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393096 2021-04-22T17:29:33 Z asbsfds Ili (COI17_ili) C++14
0 / 100
180 ms 392484 KB
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;
typedef long long llint;

const int maxn = 2e4+10;
const int base = 31337;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;

int n, m;
bool dp[maxn][maxn];
vector< int > graph[maxn];
char out[maxn];

int get() {
	char type;
	scanf(" %c", &type);
	
	int x;
	scanf("%d", &x); x--;
	if (type == 'c') x += n;
	return x;
}

void dfs(int x) {
	out[x] = '0';
	for (int i = 0; i < graph[x].size(); i++) {
		int tren = graph[x][i];
		dfs(tren);
	}
}

int main() {
	scanf("%d%d", &n, &m);
	memset(out, '?', sizeof out);
	for (int i = 0; i < m; i++) {
		scanf(" %c", out+(n + i));
	}
	
	for (int i = 0; i < m; i++) {
		graph[i + n].push_back(get());
		graph[i + n].push_back(get());
	}
	
	for (int i = n; i < m + n; i++) {
		if (out[i] == '0') {
			dfs(i);
		}
	}
	
	for (int i = n; i < m + n; i++) {
		bool flag = true;
		for (int j = 0; j < graph[i].size(); j++) {
			int tren = graph[i][j];
			if (out[tren] != '0') flag = false;
		}
		if (flag) out[i] = '0';
	}
	
	memset(dp, false, sizeof dp);
	for (int i = 0; i < m + n; i++) if (out[i] != '0') dp[i][i] = true;
	for (int i = n; i < m + n; i++) {
		for (int j = 0; j < graph[i].size(); j++) {
			int tren = graph[i][j];
			for (int l = 0; l < n; l++) {
				if (dp[tren][l]) dp[i][l] = true;
			}
		}
	}
	
	for (int i = n; i < m + n; i++) {
		for (int j = n; j < i; j++) {
			bool flag = true;
			for (int x = 0; x < graph[j].size(); x++) {
				int tren = graph[j][x];
				if (dp[j][tren] && !dp[i][tren]) flag = false;
			}
			if (flag) dp[i][j] = true;
		}
	}
	for (int i = 0; i < m + n; i++) {
		if (out[i] != '1') continue;
		for (int j = i + 1; j < m + n; j++) {
			if (dp[j][i]) out[j] = '1';
		}
	}
	
	/**
	for (int i = 0; i < n + m; i++) {
		for (int j = 0; j < n + m; j++) 
			printf("%d", dp[i][j]);
		printf("\n");
	}
	
	printf("debug: "); for (int i = 0; i < n + m; i++) printf("%c", out[i]); printf("\n");
	**/
	for (int i = n; i < n + m; i++) printf("%c", out[i]);
	return 0;
}

Compilation message

ili.cpp: In function 'void dfs(int)':
ili.cpp:33:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |  for (int i = 0; i < graph[x].size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~~
ili.cpp: In function 'int main()':
ili.cpp:59:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for (int j = 0; j < graph[i].size(); j++) {
      |                   ~~^~~~~~~~~~~~~~~~~
ili.cpp:69:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |   for (int j = 0; j < graph[i].size(); j++) {
      |                   ~~^~~~~~~~~~~~~~~~~
ili.cpp:80:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |    for (int x = 0; x < graph[j].size(); x++) {
      |                    ~~^~~~~~~~~~~~~~~~~
ili.cpp: In function 'int get()':
ili.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |  scanf(" %c", &type);
      |  ~~~~~^~~~~~~~~~~~~~
ili.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |  scanf("%d", &x); x--;
      |  ~~~~~^~~~~~~~~~
ili.cpp: In function 'int main()':
ili.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
ili.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |   scanf(" %c", out+(n + i));
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 180 ms 392452 KB Output is correct
2 Correct 175 ms 392484 KB Output is correct
3 Incorrect 176 ms 392448 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 180 ms 392452 KB Output is correct
2 Correct 175 ms 392484 KB Output is correct
3 Incorrect 176 ms 392448 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 180 ms 392452 KB Output is correct
2 Correct 175 ms 392484 KB Output is correct
3 Incorrect 176 ms 392448 KB Output isn't correct
4 Halted 0 ms 0 KB -