답안 #145331

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
145331 2019-08-19T15:48:03 Z arayi Ili (COI17_ili) C++17
100 / 100
3738 ms 61176 KB
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#define fr first
#define sc second
#define MP make_pair
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define lli long long int
#define y1 arayikhalatyan
using namespace std;

lli gcd(lli a, lli b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
lli cg(lli n) {
	return n ^ (n >> 1);
}
lli SUM(lli a)
{
	return (a * (a + 1) / 2);
}
bool CAN(int x, int y, int n, int m)
{
	if (x >= 0 && y >= 0 && x < n && y < m)
	{
		return true;
	}
	return false;
}
double her(double x1, double y1, double x2, double y2)
{
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
string strsum(string a, string b)
{
	int p = 0;
	string c;
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	if (b.length() < a.length())
	{
		for (int i = b.length(); i < a.length(); i++)
		{
			b += "0";
		}
	}
	else
	{
		for (int i = a.length(); i < b.length(); i++)
		{
			a += "0";
		}
	}

	a += "0", b += "0";
	for (int i = 0; i < a.length(); i++)
	{
		c += (a[i] - '0' + b[i] - '0' + p) % 10 + '0';
		p = (a[i] + b[i] - '0' - '0' + p) / 10;
	}
	if (c[c.length() - 1] == '0') c.erase(c.length() - 1, 1);
	reverse(c.begin(), c.end());
	return c;
}
string strmin(string a, string b)
{
	if (a.length() > b.length()) return b;
	if (b.length() > a.length()) return a;
	for (int i = 0; i < a.length(); i++)
	{
		if (a[i] > b[i]) return b;
		if (b[i] > a[i]) return a;
	}
	return a;
}

char vow[] = { 'a', 'e', 'i', 'o', 'u' };
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };



const int N = 1e6 + 30;
const lli mod = 1000000007;
int n, m, k;
string s;
bitset <10010> a[10100], zro, sm;
vector <int> p[N], p1[N];
queue <int> fp;
bool col[N];
int main()
{
	fastio;
	cin >> n >> m;
	cin >> s;
	for (int i = 0; i < m; i++)
	{
		char A, B;
		int a1, b1;
		cin >> A >> a1;
		cin >> B >> b1;
		if (A == 'x') a[i + 1][a1] = 1, p1[a1].PB(i + 1);
		else a[i + 1] = (a[i + 1] | a[a1]), p[a1].PB(i + 1);
		if (B == 'x') a[i + 1][b1] = 1, p1[b1].PB(i + 1);
		else a[i + 1] = (a[i + 1] | a[b1]), p[b1].PB(i + 1);;
		if (s[i] == '0') zro = (zro | a[i + 1]);
	}
	for (int i = 0; i < m; i++)
	{
		if (s[i] == '?' && (a[i + 1] & zro) == a[i + 1])
			s[i] = '0';
		else if(s[i] == '?')
		{
			sm = (a[i + 1] | zro);
			for (int j = 1; j <= n; j++)
			{
				if (!sm[j])
				{
					for (auto q : p1[j])
					{
						if (!col[q])
							fp.push(q), col[q] = true;
					}
				}
			}
			while (!fp.empty())
			{
				k = fp.front();
				fp.pop();
				for (auto q : p[k]) if (!col[q]) col[q] = true, fp.push(q);
			}
			for (int j = 0; j < m; j++)
			{
				if (s[j] == '1' && !col[j + 1])
				{
					s[i] = '1';
				}
			}
			memset(col, 0, sizeof(col));
		}
	}
	cout << s;
	return 0;
}

Compilation message

ili.cpp: In function 'std::__cxx11::string strsum(std::__cxx11::string, std::__cxx11::string)':
ili.cpp:58:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = b.length(); i < a.length(); i++)
                            ~~^~~~~~~~~~~~
ili.cpp:65:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = a.length(); i < b.length(); i++)
                            ~~^~~~~~~~~~~~
ili.cpp:72:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < a.length(); i++)
                  ~~^~~~~~~~~~~~
ili.cpp: In function 'std::__cxx11::string strmin(std::__cxx11::string, std::__cxx11::string)':
ili.cpp:85:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < a.length(); i++)
                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 48376 KB Output is correct
2 Correct 47 ms 48376 KB Output is correct
3 Correct 54 ms 48296 KB Output is correct
4 Correct 48 ms 48376 KB Output is correct
5 Correct 48 ms 48504 KB Output is correct
6 Correct 49 ms 48292 KB Output is correct
7 Correct 47 ms 48248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 48376 KB Output is correct
2 Correct 47 ms 48376 KB Output is correct
3 Correct 54 ms 48296 KB Output is correct
4 Correct 48 ms 48376 KB Output is correct
5 Correct 48 ms 48504 KB Output is correct
6 Correct 49 ms 48292 KB Output is correct
7 Correct 47 ms 48248 KB Output is correct
8 Correct 66 ms 48936 KB Output is correct
9 Correct 67 ms 48760 KB Output is correct
10 Correct 62 ms 48888 KB Output is correct
11 Correct 73 ms 48888 KB Output is correct
12 Correct 58 ms 48888 KB Output is correct
13 Correct 64 ms 49016 KB Output is correct
14 Correct 72 ms 49020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 48376 KB Output is correct
2 Correct 47 ms 48376 KB Output is correct
3 Correct 54 ms 48296 KB Output is correct
4 Correct 48 ms 48376 KB Output is correct
5 Correct 48 ms 48504 KB Output is correct
6 Correct 49 ms 48292 KB Output is correct
7 Correct 47 ms 48248 KB Output is correct
8 Correct 66 ms 48936 KB Output is correct
9 Correct 67 ms 48760 KB Output is correct
10 Correct 62 ms 48888 KB Output is correct
11 Correct 73 ms 48888 KB Output is correct
12 Correct 58 ms 48888 KB Output is correct
13 Correct 64 ms 49016 KB Output is correct
14 Correct 72 ms 49020 KB Output is correct
15 Correct 802 ms 55964 KB Output is correct
16 Correct 1492 ms 57308 KB Output is correct
17 Correct 1258 ms 59128 KB Output is correct
18 Correct 3738 ms 60928 KB Output is correct
19 Correct 1166 ms 57376 KB Output is correct
20 Correct 2555 ms 60936 KB Output is correct
21 Correct 3552 ms 61176 KB Output is correct
22 Correct 859 ms 60624 KB Output is correct
23 Correct 898 ms 61112 KB Output is correct
24 Correct 874 ms 61068 KB Output is correct
25 Correct 898 ms 60792 KB Output is correct
26 Correct 893 ms 60636 KB Output is correct
27 Correct 909 ms 60680 KB Output is correct
28 Correct 840 ms 60356 KB Output is correct
29 Correct 852 ms 60408 KB Output is correct
30 Correct 858 ms 60536 KB Output is correct
31 Correct 936 ms 61048 KB Output is correct
32 Correct 1004 ms 61004 KB Output is correct