#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ld long double
#define ll long long
#define S second
#define F first
using namespace __gnu_pbds;
using namespace std;
typedef tree<long long, null_type, less_equal<long long>,
rb_tree_tag, tree_order_statistics_node_update> Tree;
const ll INF = 9223372036854775807LL;
const ll inf = 2147483647;
const ll MAXN = 200010;
const ll MOD = 1e9 + 7;
const ld PI = acos(-1);
const ll NROOT = 320;
ll binpow(ll a, ll b) {
ll res = 1;
for (;b; b /= 2, a *= a, a %= MOD)
if (b & 1) res *= a, res %= MOD;
return res % MOD;
}
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
ll invmod(ll a) {return binpow(a, MOD - 2);}
int stroi(string s) {
int ans = 0;
for (int i = 0; i < s.size(); i ++) {
ans *= 10;
ans += (s[i] - '0');
}
return ans;
}
bool is(string b) {
if (b[0] >= 'a' && b[0] <= 'z') {
return 1;
}
return 0;
}
int32_t main () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
vector<string> a(n + 1), b(n + 1);
map<string, int> v;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
if (is(a[i])) {
v[a[i]] = -1;
}
}
for (int i = 1; i <= n; i ++) {
cin >> b[i];
if (is(b[i])) {
v[b[i]] = -1;
}
}
for (int i = 1; i <= n; i ++) {
if (!is(a[i]) && !is(b[i])) {
if (a[i] != b[i]) {
cout << "NE\n";
return 0;
}
} else if (is(a[i])) {
if (is(b[i])) {
if (v[a[i]] != -1) {
if (v[b[i]] == -1) v[b[i]] == v[a[i]];
else if (v[b[i]] != v[a[i]]) {
cout << "NE\n";
return 0;
}
}
} else {
if (v[a[i]] != -1 && v[a[i]] != stroi(b[i])) {
cout << "NE\n";
return 0;
} else if (v[a[i]] == -1) {
v[a[i]] = stroi(b[i]);
}
}
} else if (is(b[i])) {
if (v[b[i]] == -1) v[b[i]] = stroi(a[i]);
else if (v[b[i]] != -1 && v[b[i]] != stroi(a[i])) {
cout << "NE\n";
return 0;
}
}
}
/*for (int i = 1; i <= n; i ++) {
if (is(a[i])) cout << v[a[i]] << " ";
else cout << a[i] << " ";
} cout << "\n";
for (int i = 1; i <= n; i ++) {
if (is(b[i])) cout << v[b[i]] << " ";
else cout << b[i] << " ";
} cout << "\n";*/
for (int i = 1; i <= n; i ++) {
if (is(a[i]) && is(b[i])) {
if (v[a[i]] != -1 && v[b[i]] != -1 && v[a[i]] != v[b[i]]) {
cout << "NE\n";
return 0;
}
} else if (is(a[i])) {
if (v[a[i]] != -1 && v[a[i]] != stoi(b[i])) {
cout << "NE\n";
return 0;
}
} else if (is(b[i])) {
if (v[b[i]] != -1 && v[b[i]] != stroi(a[i])) {
cout << "NE\n";
return 0;
}
}
}
cout << "DA\n";
return 0;
}
Compilation message
zamjena.cpp: In function 'int stroi(std::string)':
zamjena.cpp:35:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int i = 0; i < s.size(); i ++) {
| ~~^~~~~~~~~~
zamjena.cpp: In function 'int32_t main()':
zamjena.cpp:80:38: warning: value computed is not used [-Wunused-value]
80 | if (v[b[i]] == -1) v[b[i]] == v[a[i]];
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
3 ms |
596 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
1364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |