Submission #26374

# Submission time Handle Problem Language Result Execution time Memory
26374 2017-06-29T12:42:01 Z youngyojun Ili (COI17_ili) C++11
100 / 100
3533 ms 2144 KB
/// 010-5330-7849
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <tuple>
#define rf(x) (x)=0;while(*p<48)im=*p=='-';while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);if(im)(x)=-(x);
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
#define MAXN (10005)
#define MAXM (10005)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;

char A[MAXM][2]; int B[MAXM][2];
char C[MAXM], D[MAXN];
char str[MAXM];
int N, M;

char& read(char x, int i) { return ('x' == x) ? D[i] : C[i]; }
char& read(int i, int j) { return read(A[i][j], B[i][j]); }
bool f() {
	for(int i = 1; i <= M; i++) C[i] = str[i];
	fill(D+1, D+N+1, '?');
	for(int i = M; i; i--) {
		if('0' == C[i]) {
			if('1' == read(i, 0) || '1' == read(i, 1)) return false;
			read(i, 0) = read(i, 1) = '0';
		}
		else if('1' == C[i]) {
			if('0' == read(i, 0) && '0' == read(i, 1)) return false;
			if('0' == read(i, 0)) read(i, 1) = '1';
			else if('0' == read(i, 1)) read(i, 0) = '1';
		}
	}
	for(int i = 1; i <= M; i++) {
		if('0' == C[i]) {
			if('1' == read(i, 0) || '1' == read(i, 1)) return false;
			read(i, 0) = read(i, 1) = '0';
		} else if('1' == C[i]) {
			if('0' == read(i, 0) && '0' == read(i, 1)) return false;
			if('?' == read(i, 0)) read(i, 0) = '1';
			if('?' == read(i, 1)) read(i, 1) = '1';
		} else {
			if('0' == read(i, 0) && '0' == read(i, 1)) C[i] = '0';
			else {
				if('?' == read(i, 0)) read(i, 0) = '1';
				if('?' == read(i, 1)) read(i, 1) = '1';
				C[i] = '1';
			}
		}
	}
	return true;
}
int main() {
	scanf("%d%d %s", &N, &M, str+1);
	for(int i = 1; i <= M; i++) {
		for(int j = 0; j < 2; j++) {
			scanf(" %c%d", &A[i][j], &B[i][j]);
		}
	}
	for(int i = 1; i <= M; i++) {
		if('?' != str[i]) { putchar(str[i]); continue; }
		str[i] = '0'; bool bumsoo1 = f();
		str[i] = '1'; bool bumsoo2 = f(); str[i] = '?';
		if(bumsoo1 && !bumsoo2) putchar('0');
		else if(!bumsoo1 && bumsoo2) putchar('1');
		else putchar('?');
	}
	putchar('\n');
	return 0;
}

Compilation message

ili.cpp: In function 'int main()':
ili.cpp:83:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d %s", &N, &M, str+1);
                                 ^
ili.cpp:86:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf(" %c%d", &A[i][j], &B[i][j]);
                                      ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2144 KB Output is correct
2 Correct 0 ms 2144 KB Output is correct
3 Correct 0 ms 2144 KB Output is correct
4 Correct 0 ms 2144 KB Output is correct
5 Correct 0 ms 2144 KB Output is correct
6 Correct 0 ms 2144 KB Output is correct
7 Correct 0 ms 2144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2144 KB Output is correct
2 Correct 0 ms 2144 KB Output is correct
3 Correct 0 ms 2144 KB Output is correct
4 Correct 0 ms 2144 KB Output is correct
5 Correct 0 ms 2144 KB Output is correct
6 Correct 0 ms 2144 KB Output is correct
7 Correct 0 ms 2144 KB Output is correct
8 Correct 0 ms 2144 KB Output is correct
9 Correct 0 ms 2144 KB Output is correct
10 Correct 0 ms 2144 KB Output is correct
11 Correct 3 ms 2144 KB Output is correct
12 Correct 0 ms 2144 KB Output is correct
13 Correct 0 ms 2144 KB Output is correct
14 Correct 0 ms 2144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2144 KB Output is correct
2 Correct 0 ms 2144 KB Output is correct
3 Correct 0 ms 2144 KB Output is correct
4 Correct 0 ms 2144 KB Output is correct
5 Correct 0 ms 2144 KB Output is correct
6 Correct 0 ms 2144 KB Output is correct
7 Correct 0 ms 2144 KB Output is correct
8 Correct 0 ms 2144 KB Output is correct
9 Correct 0 ms 2144 KB Output is correct
10 Correct 0 ms 2144 KB Output is correct
11 Correct 3 ms 2144 KB Output is correct
12 Correct 0 ms 2144 KB Output is correct
13 Correct 0 ms 2144 KB Output is correct
14 Correct 0 ms 2144 KB Output is correct
15 Correct 713 ms 2144 KB Output is correct
16 Correct 1439 ms 2144 KB Output is correct
17 Correct 1653 ms 2144 KB Output is correct
18 Correct 2353 ms 2144 KB Output is correct
19 Correct 1556 ms 2144 KB Output is correct
20 Correct 3423 ms 2144 KB Output is correct
21 Correct 3533 ms 2144 KB Output is correct
22 Correct 476 ms 2144 KB Output is correct
23 Correct 499 ms 2144 KB Output is correct
24 Correct 486 ms 2144 KB Output is correct
25 Correct 943 ms 2144 KB Output is correct
26 Correct 879 ms 2144 KB Output is correct
27 Correct 899 ms 2144 KB Output is correct
28 Correct 879 ms 2144 KB Output is correct
29 Correct 876 ms 2144 KB Output is correct
30 Correct 889 ms 2144 KB Output is correct
31 Correct 846 ms 2144 KB Output is correct
32 Correct 886 ms 2144 KB Output is correct