이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define DEBUG false
using namespace std;
class Node {
public :
Node *c[26];
bool finish;
Node() : finish(false) {
for(int i = 0; i < 26; i++) {
c[i] = NULL;
}
}
};
void add(Node *node, string s, int idx) {
if(idx == s.length()) {
node->finish = true;
return;
}
int v = s[idx] - 'a';
if(node->c[v] == NULL) {
node->c[v] = new Node();
}
add(node->c[v], s, idx + 1);
}
bool solve(Node *node1, Node *node2, bool turn) {
bool ok;
if(turn == true) { // Nina
if(node1 == NULL) {
return false;
}
ok = false;
for(int i = 0; i < 26; i++) {
if(node1->c[i] != NULL) {
ok |= solve(node1->c[i], node2->c[i], turn ^ true);
}
}
}
else { // Emilija
if(node2 == NULL) {
return true;
}
ok = true;
for(int i = 0; i < 26; i++) {
if(node2->c[i] != NULL) {
ok &= solve(node1->c[i], node2->c[i], turn ^ true);
}
}
}
return ok;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
Node *root1 = new Node();
for(int i = 1; i <= n; i++) {
string s;
cin >> s;
add(root1, s, 0);
}
int m;
cin >> m;
Node *root2 = new Node();
for(int i = 1; i <= m; i++) {
string s;
cin >> s;
add(root2, s, 0);
}
if(solve(root1, root2, true) == true) {
cout << "Nina";
}
else {
cout << "Emilija";
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void add(Node*, std::string, int)':
Main.cpp:17:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | if(idx == s.length()) {
| ~~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |