# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
470194 | Karabasan | Zamjena (COCI18_zamjena) | C++17 | 20 ms | 4556 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>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forcin for(int i=0;i<n;i++) scanf("%d",&dizi[i]);
#define forcout for(int i=0;i<n;i++) printf("%d ",dizi[i]);
#define ll long long
using namespace std;
int n,t;
string dizi[50005];
string dizi1[50005];
int diziyan[50005];
int dizi1yan[50005];
map<string,int> mp;
int main()
{
fast;
scanf("%d",&n);
for(int i=0;i<n;i++)
cin>>dizi[i];
for(int i=0;i<n;i++)
cin>>dizi1[i];
for(int i=0;i<n;i++)
{
if(dizi[i][0]=='0'||dizi[i][0]=='1'||dizi[i][0]=='2'||dizi[i][0]=='3'||dizi[i][0]=='4'||dizi[i][0]=='5'||dizi[i][0]=='6'||dizi[i][0]=='7'||dizi[i][0]=='8'||dizi[i][0]=='9')
{
diziyan[i]=stoi(dizi[i]);
}
}
for(int i=0;i<n;i++)
{
if(dizi1[i][0]=='0'||dizi1[i][0]=='1'||dizi1[i][0]=='2'||dizi1[i][0]=='3'||dizi1[i][0]=='4'||dizi1[i][0]=='5'||dizi1[i][0]=='6'||dizi1[i][0]=='7'||dizi1[i][0]=='8'||dizi1[i][0]=='9')
{
dizi1yan[i]=stoi(dizi1[i]);
}
}
for(int i=0;i<n;i++)
{
if(diziyan[i]!=0&&dizi1yan[i]==0)
{
if(mp[dizi1[i]]!=0&&mp[dizi1[i]]!=diziyan[i])
{
printf("NE");
return 0;
}
mp[dizi1[i]]=diziyan[i];
dizi1[i]=dizi[i];
}
else if(diziyan[i]==0&&dizi1yan[i]!=0)
{
if(mp[dizi[i]]!=0&&mp[dizi[i]]!=dizi1yan[i])
{
printf("NE");
return 0;
}
mp[dizi[i]]=dizi1yan[i];
dizi[i]=dizi1[i];
}
else if(diziyan[i]==0&&dizi1yan[i]==0)
{
if(mp[dizi[i]]==0&&mp[dizi1[i]]==0)
continue;
else if (mp[dizi[i]]==0&&mp[dizi1[i]]!=0)
{
mp[dizi[i]]=mp[dizi1[i]];
dizi[i]=dizi1[i];
}
else if(mp[dizi[i]]!=0&&mp[dizi1[i]]==0)
{
mp[dizi1[i]]=mp[dizi[i]];
dizi1[i]=dizi[i];
}
else if(mp[dizi[i]]!=mp[dizi1[i]])
{
printf("NE");
return 0;
}
else if(mp[dizi[i]]==mp[dizi1[i]])
{
dizi[i]=to_string(mp[dizi[i]]);
dizi1[i]=to_string(mp[dizi1[i]]);
}
}
}
for(int i=0;i<n;i++)
{
if(diziyan[i]!=0&&dizi1yan[i]==0)
{
if(mp[dizi1[i]]!=0&&mp[dizi1[i]]!=diziyan[i])
{
printf("NE");
return 0;
}
mp[dizi1[i]]=diziyan[i];
dizi1[i]=dizi[i];
}
else if(diziyan[i]==0&&dizi1yan[i]!=0)
{
if(mp[dizi[i]]!=0&&mp[dizi[i]]!=dizi1yan[i])
{
printf("NE");
return 0;
}
mp[dizi[i]]=dizi1yan[i];
dizi[i]=dizi1[i];
}
else if(diziyan[i]==0&&dizi1yan[i]==0)
{
if(mp[dizi[i]]==0&&mp[dizi1[i]]==0)
continue;
else if (mp[dizi[i]]==0&&mp[dizi1[i]]!=0)
{
mp[dizi[i]]=mp[dizi1[i]];
dizi[i]=dizi1[i];
}
else if(mp[dizi[i]]!=0&&mp[dizi1[i]]==0)
{
mp[dizi1[i]]=mp[dizi[i]];
dizi1[i]=dizi[i];
}
else if(mp[dizi[i]]!=mp[dizi1[i]])
{
printf("NE");
return 0;
}
else if(mp[dizi[i]]==mp[dizi1[i]])
{
dizi[i]=to_string(mp[dizi[i]]);
dizi1[i]=to_string(mp[dizi1[i]]);
}
}
}
for(int i=0;i<n;i++)
{
if(dizi[i][0]=='0'||dizi[i][0]=='1'||dizi[i][0]=='2'||dizi[i][0]=='3'||dizi[i][0]=='4'||dizi[i][0]=='5'||dizi[i][0]=='6'||dizi[i][0]=='7'||dizi[i][0]=='8'||dizi[i][0]=='9')
{
diziyan[i]=stoi(dizi[i]);
}
}
for(int i=0;i<n;i++)
{
if(dizi1[i][0]=='0'||dizi1[i][0]=='1'||dizi1[i][0]=='2'||dizi1[i][0]=='3'||dizi1[i][0]=='4'||dizi1[i][0]=='5'||dizi1[i][0]=='6'||dizi1[i][0]=='7'||dizi1[i][0]=='8'||dizi1[i][0]=='9')
{
dizi1yan[i]=stoi(dizi1[i]);
}
}
for(int i=0;i<n;i++)
{
if(diziyan[i]==0&&dizi1yan[i]==0)
continue;
else
{
if(dizi[i]!=dizi1[i])
{
printf("NE");
return 0;
}
}
}
printf("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... |