# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
464620 | aihay | Zamjena (COCI18_zamjena) | C++14 | 24 ms | 32336 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.
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef int in;
#define int long long
#define f first
#define s second
#define pb push_back
#define pp push
#define double long double
#define ceil(x,y) (x/y)+(x%y!=0)*((double)(1.0*x/y)<0?0:1)
#define floor(x,y) (x/y)+(x%y!=0)*((double)(1.0a*x/y)<0?-1:0)
const int MAX=1e7;
const int MOD=1e9+7;
const int MAAX=1e18;
int arr[500010],arr2[500010];
string s[500010],s2[500010];
map<string,int> mp;
in main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int tc=1;
//cin>>tc;
while(tc--){
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>s[i];
if(s[i][0]>='0'&&s[i][0]<='9'){
for(int j=0;j<s[i].size();j++){
arr[i]*=10;
arr[i]+=s[i][j]-'0';
}
s[i]="";
}
else{
arr[i]=-1;
}
}
for(int i=0;i<n;i++){
cin>>s2[i];
if(s2[i][0]>='0'&&s2[i][0]<='9'){
for(int j=0;j<s2[i].size();j++){
arr2[i]*=10;
arr2[i]+=s2[i][j]-'0';
}
s2[i]="";
}
else{
arr2[i]=-1;
}
if(~arr2[i]&&~arr[i])
continue;
if(~arr[i]){
arr2[i]=arr[i];
mp[s2[i]]=arr[i];
continue;
}
if(~arr2[i]){
arr[i]=arr2[i];
mp[s[i]]=arr[i];
continue;
}
}
for(int i=0;i<n;i++){
if(arr2[i]==-1&&arr[i]==-1){
if(mp[s[i]]&&mp[s2[i]]==0){
mp[s2[i]]=mp[s[i]];
}
else if(mp[s2[i]]&&mp[s[i]]==0)
mp[s[i]]=mp[s2[i]];
else if(mp[s[i]]==0)
mp[s[i]]=mp[s2[i]]=1;
arr[i]=mp[s[i]];
arr2[i]=mp[s2[i]];
}
if(arr[i]!=arr2[i]||arr[i]==-1||arr2[i]==-1){
cout<<"NE\n";
return 0;
}
}
cout<<"DA\n";
}
}
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... |