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;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
int n;
string s[50005], t[50005];
map<string, vector<int> > mp;
int stuf[50005], val;
bool die = 0;
void dfs(string bruh){
for(auto i : mp[bruh]){
if(!stuf[i])stuf[i] = val;
else {
if(stuf[i] != val)die = 1;
continue;
}
if(s[i] != bruh && (s[i][0] < '0' || s[i][0] > '9'))dfs(s[i]);
if(t[i] != bruh && (t[i][0] < '0' || t[i][0] > '9'))dfs(t[i]);
}
}
void solve(){
cin >> n;
for(int i=1;i<=n;i++)cin >> s[i];
for(int i=1;i<=n;i++)cin >> t[i];
for(int i=1;i<=n;i++){
if(s[i][0] >= '0' && s[i][0] <= '9')continue;
mp[s[i]].push_back(i);
}
for(int i=1;i<=n;i++){
if(t[i][0] >= '0' && t[i][0] <= '9')continue;
mp[t[i]].push_back(i);
}
for(int i=1;i<=n;i++){
if(s[i][0] < '0' || s[i][0] > '9'){
if((t[i][0] >= '0' && t[i][0] <= '9')){
val = 0;
for(auto j : t[i])val = val * 10 + (j - '0');
dfs(s[i]);
}
else if(stuf[i]){
val = stuf[i];
dfs(s[i]);
}
}
if(t[i][0] < '0' || t[i][0] > '9'){
if(s[i][0] >= '0' && s[i][0] <= '9'){
val = 0;
for(auto j : s[i])val = val * 10 + (j - '0');
dfs(t[i]);
}
else if(stuf[i]){
val = stuf[i];
dfs(t[i]);
}
}
else if((s[i][0] >= '0' && s[i][0] <= '9') && (t[i][0] >= '0' && t[i][0] <= '9')){
int val2 = 0, val3 = 0;
for(auto j : s[i])val2 = val2 * 10 + (j - '0');
for(auto j : t[i])val3= val3 * 10 + (j - '0');
if(val2 != val3)die = 1;
}
}
cout << (die ? "NE" : "DA");
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int tc = 1;
//cin >> tc;
for(int tc1=1;tc1<=tc;tc1++){
// cout << "Case #" << tc1 << ": ";
solve();
}
}
Compilation message (stderr)
zamjena.cpp:76:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
76 | main(){
| ^~~~
# | 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... |