# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
105491 | JakubLap | Palinilap (COI16_palinilap) | C++14 | 3 ms | 384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 1024;
map<long long, int> ID;
bitset<N> a[N];
int n;
long long getCode(string s) {
long long ans = 0;
for (int i = 0; i < s.size(); ++i)
ans = ans * 26 + (s[i] - 'a');
return ans;
}
int main() {
ios::sync_with_stdio(false);
int nQuery; cin >> nQuery;
while (nQuery--) {
string u; cin >> u;
long long u_code = getCode(u);
char colon; cin >> colon;
string v;
vector<int> adj;
bool fail = ID.count(u_code);
while (cin >> v) {
if (v == ";") break;
long long code = getCode(v);
if (!ID.count(code)) {
fail = true;
} else {
adj.push_back(ID[code]);
}
}
if (fail) {
cout << "greska\n";
continue;
}
sort(adj.begin(), adj.end(), greater<int>());
bitset<N> was;
for (int i = 0; i < adj.size(); ++i) {
int v = adj[i];
bool isRoot = true;
for (int j = 0; j < i; ++j) if (a[adj[j]].test(v)) {
isRoot = false;
break;
}
if (isRoot) {
if ((was & a[v]).any()) {
fail = true;
break;
}
was |= a[v];
}
}
if (fail) {
cout << "greska\n";
continue;
}
cout << "ok\n";
ID[u_code] = ++n;
for (int v : adj) {
a[n] |= a[v];
a[n].set(v);
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |