Submission #233284

# Submission time Handle Problem Language Result Execution time Memory
233284 2020-05-20T08:36:59 Z NONAME Tenis (COI19_tenis) C++17
0 / 100
500 ms 8152 KB
#include <bits/stdc++.h>
#define sz(x) int(x.size())
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#define N 100500
#define oo ll(1e16)
#define ft first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define el '\n'
#define elf endl
#define base ll(1e9 + 7)
using namespace std;
typedef long long ll;
typedef long double ld;

int n, q, pos[3][N], a[3][N];
bool mk[N];

bool f(int v) {
	set <int> s;

	fill(mk, mk + n, 0);

	queue <int> q;
	q.push(v);

//	for (int i = 0; i < 3; i++, cerr << el)
//    for (int j = 0; j < n; j++)
//        cerr << a[i][j] + 1 << ' ';
//    cerr << el;

    while (!q.empty()) {
        s.clear();

		int v = q.front();
		q.pop();

		for (int t = 0; t < 3; t++)
		for (int i = pos[t][v]; i < n; i++) {
			int x = a[t][i];
			if (x == v)
                continue;

            if (mk[x])
				break;

			s.insert(x);
		}

		for (int x : s)
			mk[x] = 1, q.push(x);
    }

    bool ok = 1;

    for (int i = 0; i < n; i++)
		ok &= mk[i];

	return ok;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//    in("input.txt");

	cin >> n >> q;
	for (int t = 0; t < 3; t++)
	for (int i = 0; i < n; i++) {
		cin >> a[t][i];
		a[t][i]--;

        pos[t][a[t][i]] = i;
	}

	while (q--) {
		int type;
		cin >> type;

		if (type == 1) {
			int x;
			cin >> x;
			x--;

			bool ok = f(x);

			cout << ((ok) ? "DA" : "NE") << el;
		}

		if (type == 2) {
            int x, y, z;
            cin >> x >> y >> z;
            x--; y--; z--;

            swap(pos[x][y], pos[x][z]);
			swap(a[x][pos[x][y]], a[x][pos[x][z]]);
		}
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 8152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -