#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 10004;
int n, m;
bitset<N> a[N];
pair<pair<char, int>, pair<char, int> > g[N];
char anss[N], ans[N];
bitset<N> x0;
int main()
{
cin >> n >> m;
cin >> anss;
for (int i = 1; i <= m; ++i)
ans[i] = anss[i - 1];
for (int i = 1; i <= m; ++i)
{
char s1, s2;
int x1, x2;
cin >> s1 >> x1 >> s2 >> x2;
if (s1 == 'c')
a[i] = a[x1];
else
a[i][x1] = 1;
if (s2 == 'c')
a[i] = (a[i] | a[x2]);
else
a[i][x2] = 1;
g[i] = m_p(m_p(s1, x1), m_p(s2, x2));
}
for (int i = 1; i <= m; ++i)
{
if (ans[i] == '0')
{
x0 = (x0 | a[i]);
}
}
for (int i = 1; i <= m; ++i)
{
if ((a[i] & x0) == a[i])
ans[i] = '0';
}
for (int i = 1; i <= m; ++i)
{
bitset<N> z = (a[i] | x0);
for (int j = 1; j <= n; ++j)
{
bool z1 = false, z2 = false;
if (g[j].first.first == 'x')
{
if (z[g[j].first.second] == 1)
z1 = true;
}
else
{
if (anss[g[j].first.second] == '0')
z1 = true;
}
if (g[j].second.first == 'x')
{
if (z[g[j].second.second] == 1)
z2 = true;
}
else
{
if (anss[g[j].second.second] == '0')
z2 = true;
}
if (z1 && z2)
anss[j] = '0';
else
anss[j] = ans[j];
if (ans[j] == '1' && anss[j] == '0')
{
ans[i] = '1';
break;
}
}
}
for (int i = 1; i <= m; ++i)
cout << ans[i];
cout << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Incorrect |
4 ms |
892 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Incorrect |
4 ms |
892 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |