#include <bits/stdc++.h>
using namespace std;
int n, a[50000], b[50000];
unordered_map <string, vector<int> > varA, varB;
string x[50000], y[50000];
int StrToInt(string &s)
{
int k = 0;
for(size_t i = 0; i < s.length(); i++)
k = k * 10 + s[i] - '0';
return k;
}
int main()
{
cin>>n;
string s;
for(int i = 0; i < n; i++)
{
cin>>s;
if(s[0] >= '0' && s[0] <= '9')
{
a[i] = StrToInt(s);
continue;
}
varA[s].push_back(i);
x[i] = s;
}
for(int i = 0; i < n; i++)
{
cin>>s;
if(s[0] >= '0' && s[0] <= '9')
{
b[i] = StrToInt(s);
continue;
}
varB[s].push_back(i);
y[i] = s;
}
for(int i = 0; i < n; i++)
{
int k = -1;
if(a[i] && !b[i])
{
k = a[i];
s = y[i];
}
if(!a[i] && b[i])
{
k = b[i];
s = x[i];
}
if(k == -1)
continue;
for(auto j : varA[s])
a[j] = k;
for(auto j : varB[s])
b[j] = k;
}
for(int i = 0; i < n; i++)
if(a[i] != b[i])
{
cout<<"NE"<<endl;
return 0;
}
cout<<"DA"<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3432 KB |
Output is correct |
5 |
Correct |
2 ms |
3440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3432 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
3412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
3540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
4728 KB |
Output is correct |
2 |
Incorrect |
21 ms |
6428 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |