Submission #66347

# Submission time Handle Problem Language Result Execution time Memory
66347 2018-08-10T09:33:49 Z osmanorhan Ili (COI17_ili) C++17
100 / 100
598 ms 5880 KB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cassert>
#include <vector>
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define For( i , a ) for(int i=1;i<=a;i++)
#define ort (b+s)/2
#define y2 asrwjaelkf
#define y1 asseopirwjaelkf
#define set multiset

using namespace std;

typedef long long Lint;
typedef double db;
typedef pair<int,int> ii;
typedef pair<int,char> ic;
typedef pair<db,db> dd;
typedef pair<ii,int> iii;
typedef pair<ii,ii> i4;

const int maxn = 100020;
const int maxm = 1000020;
const int MOd = 998244353;

int a, b, q;
int x[maxn], c[maxn];
int ar[maxn], bs[maxn];
ii con[maxn];
vector<int> w[maxn];

int Or( int x, int y ) {
	if( x > y ) swap( x, y );
	if( y == 0 ) return 0;
	if( y == 1 ) return 1;
	if( x == 0 || x == 2 ) return 2;
	return 1;
}

int get( string s ) {
	int x = 0;
	for(int i=1;i<s.size();i++)
		x *= 10, x += s[i]-'0';
	if( s[0] == 'c' ) x += a;
	return x;
}

bool can( int t ) {
	for(int i=1;i<=a+b;i++) bs[i] = ar[i];
	bs[t] = 0;
	for(int i=t;i>a;i--)
		if( bs[i] == 0 ) {
			if( bs[ con[i].fi ] == 1 || bs[ con[i].se ] == 1 ) return false;
			bs[ con[i].fi ] = bs[ con[i].se ] = 0;
		}
	for(int i=a+1;i<=a+b;i++) {
		int h = Or( bs[ con[i].fi ], bs[ con[i].se ] );
		if( h != 2 ) {
			if( bs[i] != 2 && bs[i] != h ) return false;
			bs[i] = h;
		}
	}
	return true;
}

int main() {

    //freopen("asd.in","r",stdin);
    //freopen("output17.txt","w",stdout);

	scanf("%d %d",&a,&b);
	for(int i=1;i<=a;i++) ar[i] = 2;
	for(int i=1;i<=b;i++) {
		char ch;
		scanf(" %c",&ch);
		if( ch == '0' ) ar[a+i] = 0;
		else if( ch == '1' ) ar[a+i] = 1;
		else ar[a+i] = 2;
	}

	for(int i=1;i<=b;i++) {
		string s1, s2;
		cin >> s1 >> s2;
	
		int t1 = get( s1 );
		int t2 = get( s2 );
		con[a+i] = ii( t1, t2 );
		w[t1].pb( a+i );
		w[t2].pb( a+i );
	}
	for(int i=a+b;i>a;i--)
		if( ar[i] == 0 ) ar[ con[i].fi ] = 0, ar[ con[i].se ] = 0;

	for(int i=a+1;i<=b+a;i++) {
		int t = i;
		if( ar[t] != 2 ) continue;
		//printf("-- %d %d\n",con[t].fi,con[t].se);
		int h1 = Or( ar[ con[t].fi ], ar[ con[t].se ] );
		if( h1 != 2 ) {
			ar[t] = h1;
		} else {
			//printf("asd %d\n",i);
			if( !can( t ) ) ar[t] = 1;
		}
	}
	for(int i=a+1;i<=b+a;i++) {
		if( ar[i] == 2 ) printf("?");
		else printf("%d",ar[i]);
	}
	printf("\n");
	return 0;
}

Compilation message

ili.cpp: In function 'int get(std::__cxx11::string)':
ili.cpp:57:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1;i<s.size();i++)
              ~^~~~~~~~~
ili.cpp: In function 'int main()':
ili.cpp:86:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&a,&b);
  ~~~~~^~~~~~~~~~~~~~~
ili.cpp:90:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c",&ch);
   ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2680 KB Output is correct
2 Correct 7 ms 2680 KB Output is correct
3 Correct 5 ms 2828 KB Output is correct
4 Correct 5 ms 2940 KB Output is correct
5 Correct 5 ms 3052 KB Output is correct
6 Correct 4 ms 3052 KB Output is correct
7 Correct 5 ms 3052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2680 KB Output is correct
2 Correct 7 ms 2680 KB Output is correct
3 Correct 5 ms 2828 KB Output is correct
4 Correct 5 ms 2940 KB Output is correct
5 Correct 5 ms 3052 KB Output is correct
6 Correct 4 ms 3052 KB Output is correct
7 Correct 5 ms 3052 KB Output is correct
8 Correct 5 ms 3052 KB Output is correct
9 Correct 5 ms 3052 KB Output is correct
10 Correct 5 ms 3056 KB Output is correct
11 Correct 6 ms 3080 KB Output is correct
12 Correct 7 ms 3104 KB Output is correct
13 Correct 6 ms 3152 KB Output is correct
14 Correct 5 ms 3152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2680 KB Output is correct
2 Correct 7 ms 2680 KB Output is correct
3 Correct 5 ms 2828 KB Output is correct
4 Correct 5 ms 2940 KB Output is correct
5 Correct 5 ms 3052 KB Output is correct
6 Correct 4 ms 3052 KB Output is correct
7 Correct 5 ms 3052 KB Output is correct
8 Correct 5 ms 3052 KB Output is correct
9 Correct 5 ms 3052 KB Output is correct
10 Correct 5 ms 3056 KB Output is correct
11 Correct 6 ms 3080 KB Output is correct
12 Correct 7 ms 3104 KB Output is correct
13 Correct 6 ms 3152 KB Output is correct
14 Correct 5 ms 3152 KB Output is correct
15 Correct 26 ms 3536 KB Output is correct
16 Correct 261 ms 3744 KB Output is correct
17 Correct 149 ms 3816 KB Output is correct
18 Correct 512 ms 4056 KB Output is correct
19 Correct 229 ms 4056 KB Output is correct
20 Correct 598 ms 4392 KB Output is correct
21 Correct 533 ms 4472 KB Output is correct
22 Correct 81 ms 4692 KB Output is correct
23 Correct 107 ms 4820 KB Output is correct
24 Correct 85 ms 5148 KB Output is correct
25 Correct 179 ms 5148 KB Output is correct
26 Correct 188 ms 5148 KB Output is correct
27 Correct 175 ms 5148 KB Output is correct
28 Correct 173 ms 5280 KB Output is correct
29 Correct 175 ms 5300 KB Output is correct
30 Correct 174 ms 5528 KB Output is correct
31 Correct 189 ms 5620 KB Output is correct
32 Correct 231 ms 5880 KB Output is correct