# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
81708 | Mouhanad_Hafez | Zamjena (COCI18_zamjena) | C++11 | 27 ms | 2964 KiB |
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;
bool ch(string s)
{
for (int i=0; i<s.size(); i++)
{
if (s[i]-'a'>=0&&s[i]-'a'<=25)return 0;
}
return 1;
}
int toint(string s)
{
int re=0;
int p=1;
for (int i=s.size()-1; i>=0; i--)
{
re+=((s[i]-'0')*p);
p*=10;
}
return re;
}
map<string,int>mp,mp1;
vector<pair<string,string>>v;
int main()
{
int n;
cin>>n;
string arr1[n+6],arr2[n+6];
for (int i=0; i<n; i++)cin>>arr1[i];
for (int i=0; i<n; i++)cin>>arr2[i];
for (int i=0; i<n; i++)
{
string s1,s2;
s1=arr1[i];
s2=arr2[i];
if (ch(s1)==1&&ch(s2)==1&&s1!=s2)
{
cout<<"NE";
return 0;
}
if (s1==s2)continue;
if (ch(s1)==0&&ch(s2)==0)
{
int x1=mp[s1],x2=mp[s2];
int y1=mp1[s1],y2=mp1[s2];
//if (x1==x2)continue;
if (x1!=x2&&y1==1&&y2==1)
{
cout<<"NE";
return 0;
}
if (x1!=x2&&y1==0&&y2==1)
{
mp[s1]=mp[s2];
mp1[s1]=1;
mp1[s2]=1;
continue;
}
if (x1!=x2&&y1==1&&y2==0)
{
mp[s2]=mp[s1];
mp1[s1]=1;
mp1[s2]=1;
continue;
}
if (y1==0&&y2==0)
{
v.push_back({s1,s2});
continue;
}
}
if (ch(s1)==1&&ch(s2)==0)
{
if (mp1[s2]==1)
{
cout<<"NE";
return 0;
}
mp[s2]=toint(s1);
mp1[s2]=1;
}
if (ch(s1)==0&&ch(s2)==1)
{
if (mp1[s1]==1)
{
cout<<"NE";
return 0;
}
mp[s1]=toint(s2);
mp1[s1]=1;
}
}
for (int i=0; i<v.size(); i++)
{
if (mp[v[i].first]!=mp[v[i].second])
{
cout<<"NE";
return 0;
}
}
cout<<"DA";
return 0;
}
Compilation message (stderr)
# | 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... |