Submission #464959

# Submission time Handle Problem Language Result Execution time Memory
464959 2021-08-14T15:41:52 Z BERNARB01 CSS (COI14_css) C++17
10 / 100
1629 ms 106756 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 5003;

int par[N];
string id[N];
bool bl[N][N], dp[N][N], vis[N][N];
set<string> clss[N];
vector<string> clf[N];

bool sol(int i, int j) {
	if (j == -1) return true;
	if (i == -1) return false;
	if (vis[i][j]) return dp[i][j];
	vis[i][j] = true;
	dp[i][j] = sol(par[i], j);
	if (bl[i][j]) dp[i][j] |= sol(par[i], j - 1);
	return dp[i][j];
}

bool ok(int i, int j) {
	for (auto x : clf[j]) {
		if (clss[i].find(x) == clss[i].end()) return false;
	}
	return true;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> stk(1, -1);
	int idd = -1;
	for (int i = 0; i < n; i++) {
		string div;
		cin >> div;
		if (div == "</div>") {
			stk.pop_back();
		} else {
			++idd;
			par[idd] = stk.back();
			stk.push_back(idd);
			cin >> id[idd];
			id[idd] = id[idd].substr(4, id[idd].length() - 5);
			string C;
			getline(cin >> ws, C);
			stringstream ss(C);
			while (ss >> C) {
				if (C.length() > 5 && C[5] == '=') {
					C = C.substr(7, C.length() - 7);
				}
				if (C.back() == '>') {
					C.pop_back();
					C.pop_back();
				}
				clss[idd].insert(C);
			}
		}
	}
	idd++;
	int m;
	cin >> m;
	while (m--) {
		//memset(dp, false, sizeof dp);
		//memset(bl, 0, sizeof bl);
		memset(vis, 0, sizeof vis);
		for (int i = 0; i < N; i++) {
			clf[i].clear();
		}
		string k;
		getline(cin >> ws, k);
		stringstream ss(k);
		int j = 0;
		while (ss >> k) {
			if (k.length() == 1) {
				assert(false);
			}
			for (char c : k) {
				if (c == '.') {
					clf[j].emplace_back();
				} else {
					clf[j].back() += c;
				}
			}
			j++;
		}
		for (int i = 0; i < idd; i++) {
			for (int jj = 0; jj < j; jj++) {
				bl[i][jj] = ok(i, jj);
			}
		}
		vector<string> res;
		for (int i = 0; i < idd; i++) {
			if (sol(i, j - 1)) {
				res.emplace_back(id[i]);
			}
		}
		cout << res.size();
		for (int i = 0; i < (int) res.size(); i++) {
			cout << " " << res[i];
		}
		cout << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 29388 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 67012 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1629 ms 75716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 216 ms 95292 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 236 ms 95368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 37 ms 51276 KB Execution killed with signal 6
# Verdict Execution time Memory Grader output
1 Runtime error 172 ms 106616 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 172 ms 106756 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 184 ms 106652 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 165 ms 106572 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -