Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*input
- 2 2
- (x1) and
- (not x2)
- */
- #include <bits/stdc++.h>
- using namespace std;
- #define sz(a) ((int)(a).size())
- #define rep(i,a,b) for (int i = (a); i < (b); i++)
- #define dec(i,n,a) for (int i = (n); i >= (a); i--)
- #define max(a, b) ((a) > (b) ? (a) : (b))
- #define MAX_N 2001
- typedef vector<int> vi;
- typedef bitset<MAX_N> bs;
- bs solve(vector<bs> &U, bs b){
- int n = sz(U);
- int l = 0;
- vi linha(n, -1);
- rep(c, 0, n) {
- int r = l;
- if (U[l][c] == 0) {
- rep(i, l + 1, n) {
- if (U[i][c]){
- r = i;
- break;
- }
- }
- }
- if (l != r) {
- swap(U[l], U[r]);
- swap(b[l], b[r]);
- }
- if (!U[l][c]) continue;
- linha[c] = l;
- rep(i, l + 1, n) {
- if(U[i][c]) {
- U[i] ^= U[l];
- b[i] = b[i] ^ b[l];
- }
- }
- l++;
- }
- rep(i, 0, n) {
- if(U[i].count() == 0 && b[i]) {
- printf("impossible\n");
- exit(0);
- }
- }
- bs x;
- dec(i, n - 1, 0) {
- x[i] = linha[i] == -1 ? 1 : b[linha[i]];
- if (x[i]) {
- rep(j, 0, i) {
- if (U[j][i]) b[j] = b[j] ^ 1;
- }
- }
- }
- return x;
- }
- int main() {
- int n, m, d;
- vector<bs> mat;
- bs x;
- scanf("%d%d", &m, &n);
- mat.resize(max(m, n));
- rep(i, 0, m) {
- scanf(" %*c");
- int v = 1;
- while (1) {
- char c;
- scanf(" %c", &c);
- if(c == 'n') {
- scanf("%*c %*c %*c");
- v ^= 1;
- }
- scanf("%d", &d);
- d--;
- mat[i][n - 1 - d] = mat[i][n - 1 - d] ^ 1;
- scanf(" %c", &c);
- if(c == 'o') scanf("%*c");
- else break;
- }
- if(i + 1 < m) scanf(" %*c %*c %*c ");
- if(v) x.set(i);
- }
- x = solve(mat, x);
- rep(i, 0, n) printf(x[n - 1 - i] ? "T" : "F");
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement