# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
245838 |
2020-07-07T14:56:58 Z |
alrad |
Zamjena (COCI18_zamjena) |
C++17 |
|
10 ms |
1536 KB |
#include <bits/stdc++.h>
using namespace std;
#define N (int)100 + 2
#define all(x) x.begin(), x.end()
bool isNum(string x) {
bool ok = true;
for (char c : x) {
int code = int(c - '0');
ok &= (0 <= code && code <= 9);
}
return ok;
}
int strToNum(string x) {
int res = 0 , base = 1;
reverse(all(x));
for (char c : x) {
int dig = int(c - '0');
res += (dig * base);
base *= 10;
}
return res;
}
int main() {
#ifdef judge
ifstream cin("input.txt");
ofstream cout("output.txt");
#endif // judge
ios_base :: sync_with_stdio(0);
cin.tie(0) , cout.tie(0);
int n;
cin >> n;
unordered_map<string , int> vars;
vector<string> a(n) , b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
if (!isNum(a[i])) {
vars[a[i]] = -1;
}
}
for (int i = 0; i < n; i++) {
cin >> b[i];
if (!isNum(b[i])) {
vars[b[i]] = -1;
}
}
vector<int> bad;
for (int i = 0; i < n; i++) {
if (a[i] == b[i]) {
continue;
}
bool isNumA = isNum(a[i]) , isNumB = isNum(b[i]);
if (isNumA && isNumB) {
cout << "NE" << '\n';
return 0;
}
if (!isNumA && !isNumB) {
bad.push_back(i);
continue;
}
if (isNumA && !isNumB) {
if (vars[b[i]] == -1) {
vars[b[i]] = strToNum(a[i]);
} else {
if (strToNum(a[i]) != vars[b[i]]) {
cout << "NE" << '\n';
return 0;
}
}
}
if (!isNumA && isNumB) {
if (vars[a[i]] == -1) {
vars[a[i]] = strToNum(b[i]);
} else {
if (strToNum(b[i]) != vars[a[i]]) {
cout << "NE" << '\n';
return 0;
}
}
}
}
for (int pos : bad) {
if (vars[a[pos]] == -1 || vars[b[pos]] == -1) {
continue;
}
if (vars[a[pos]] != vars[b[pos]]) {
cout << "NE" << '\n';
return 0;
}
}
cout << "DA" << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Incorrect |
6 ms |
768 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
1536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |