답안 #786148

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
786148 2023-07-18T04:56:08 Z 박상훈(#10027) NoM (RMI21_nom) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
bitset<10010> dp[10010], zero;
char s[10010];
pair<int, int> adj[10010];
int n, m, val[20020];

int simulate(const bitset<10010> &msk){
	for (int i=1;i<=n;i++) val[i] = ((!msk[i]) & zero[i]);
	for (int i=1;i<=m;i++){
		val[i+n] = val[adj[i].first] | val[adj[i].second];
		// printf("%d -> %d / %d %d / %d %d\n", i, val[i+n], adj[i].first, adj[i].second, val[adj[i].first], val[adj[i].second]);
		if (val[i+n]==0 && s[i]=='1') return 0;
	}

	return 1;
}

int main(){
	scanf("%d %d", &n, &m);

	scanf("%s", s+1);

	for (int i=1;i<=m;i++){
		char op1, op2;
		int x1, x2;
		scanf(" %c%d %c%d", &op1, &x1, &op2, &x2);

		if (op1=='c') x1 += n;
		if (op2=='c') x2 += n;

		adj[i] = {x1, x2};

		if (x1 > n) dp[i] |= dp[x1-n];
		else dp[i].set(x1);

		if (x2 > n) dp[i] |= dp[x2-n];
		else dp[i].set(x2);

		if (s[i]=='0') zero |= dp[i];
	}

	zero = ~zero;
	for (int i=1;i<=m;i++) if (s[i]=='?'){
		dp[i] &= zero;
		if (dp[i].count()==0) s[i] = '0';
		else if (!simulate(dp[i])) s[i] = '1';
	}

	printf("%s\n", s+1);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  scanf("%s", s+1);
      |  ~~~~~^~~~~~~~~~~
Main.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |   scanf(" %c%d %c%d", &op1, &x1, &op2, &x2);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -