# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
919496 | 2024-02-01T03:02:47 Z | silverfox | Vlak (COCI20_vlak) | C++14 | 16 ms | 22872 KB |
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define TEST "filename" using namespace std; const int maxn = 200000; class Trie { struct Node { int child[26]; int exist, cnt; }; int cur = 0; Node nodes[maxn+1]; public: Trie() { memset(nodes[0].child, -1, sizeof(nodes[0].child)); nodes[0].exist = nodes[0].cnt = 0; } int newNode() { cur++; memset(nodes[cur].child, -1, sizeof(nodes[cur].child)); nodes[cur].exist = nodes[cur].cnt = 0; return cur; } void addString(string s) { int pos = 0; for (char c: s) { int f = c - 'a'; if (nodes[pos].child[f] == -1) { nodes[pos].child[f] = newNode(); } pos = nodes[pos].child[f]; nodes[pos].cnt++; } nodes[pos].exist++; } int maxPrefix(string s) { int pos = 0; int len = 0; for (char c: s) { int f = c - 'a'; if (nodes[pos].child[f] == -1) { //prefix doesnt match anymore return len; } pos = nodes[pos].child[f]; len++; } return len; } bool findLonger(string s) { int pos = 0; for (char c: s) { int f = c - 'a'; pos = nodes[pos].child[f]; } for (int i = 0; i < 26; i++) { if (nodes[pos].child[i] != -1) { return true; } } return false; } bool letterAfterPrefix(string s) { int pos = 0; for (char c: s) { int f = c - 'a'; if (nodes[pos].child[f] == -1) { //prefix doesnt match anymore break; } pos = nodes[pos].child[f]; } for (int i = 0; i < 26; i++) { if (nodes[pos].child[i] != -1) { return true; } } return false; } bool ninaWin(string s) { int maxPref = this->maxPrefix(s); if (maxPref == s.size()) { if (this->findLonger(s)) { return false; } //B longer than A else {return s.size() % 2 == 1;} //B same length as A } else if (maxPref < s.size()) { if (this->letterAfterPrefix(s)) {return s.size() % 2 == 0; } //B and A share some prefix else { return true; } //B shorter than A } } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); if (false) { freopen(TEST".in", "r", stdin); freopen(TEST".out", "w", stdout); } int n; cin >> n; string a[n]; for (int i = 0; i < n; i++) {cin >> a[i];} int m; cin >> m; Trie trie; for (int i = 0; i < m; i++) { string s; cin >> s; trie.addString(s); } for (int i = 0; i < n; i++) { if (trie.ninaWin(a[i])) {cout << "Nina"; return 0;} } cout << "Emilija"; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 12 ms | 22360 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 22368 KB | Output is correct |
2 | Correct | 11 ms | 22316 KB | Output is correct |
3 | Correct | 11 ms | 22360 KB | Output is correct |
4 | Incorrect | 12 ms | 22180 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 22360 KB | Output is correct |
2 | Correct | 12 ms | 22360 KB | Output is correct |
3 | Incorrect | 12 ms | 22360 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 22616 KB | Output is correct |
2 | Correct | 13 ms | 22360 KB | Output is correct |
3 | Correct | 12 ms | 22360 KB | Output is correct |
4 | Incorrect | 13 ms | 22360 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 22872 KB | Output is correct |
2 | Incorrect | 15 ms | 22872 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 13 ms | 22616 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 13 ms | 22620 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |