Submission #85430

#TimeUsernameProblemLanguageResultExecution timeMemory
85430VicktorZamjena (COCI18_zamjena)C++14
14 / 70
27 ms4384 KiB
#include <iostream> #include <map> using namespace std; int N,M[500000][2],l,e,C,K; string A[50000],B[50000]; map <string,int> Hola; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin>>N; for (int i=0;i<N;i++) cin>>A[i]; for (int i=0;i<N;i++) cin>>B[i]; for (int i=0;i<N;i++) { if (A[i][0]>='0' && A[i][0]<='9') { l=A[i].size(); e=1; for (int j=l-1;j>=0;j--) { M[i][0]+=e*(A[i][j]-'0'); e*=10; } C++; } else { M[i][0]=-1; } if (B[i][0]>='0' && B[i][0]<='9') { l=B[i].size(); e=1; for (int j=l-1;j>=0;j--) { M[i][1]+=e*(B[i][j]-'0'); e*=10; } C++; } else { M[i][1]=-1; } } for (int i=0;i<N;i++) { if (M[i][0]==-1) Hola[A[i]]=-1; if (M[i][1]==-1) Hola[B[i]]=-1; } while (C<2*N) { K=C; for (int i=0;i<N;i++) { if (M[i][0]>-1 && M[i][1]>-1) { if (M[i][0]!=M[i][1]) { cout<<"NE"; return 0; } } else { if (M[i][0]>-1 || M[i][1]>-1) { if (M[i][0]==-1) { if (Hola[A[i]]==-1) { Hola[A[i]]=M[i][1]; M[i][0]=M[i][1]; C++; } else { if (Hola[A[i]]!=M[i][1]) { cout<<"NE"; return 0; } } } else { if (Hola[B[i]]==-1) { Hola[B[i]]=M[i][0]; M[i][1]=M[i][0]; C++; } else { if (Hola[B[i]]!=M[i][0]) { cout<<"NE"; return 0; } } } } } if (M[i][0]==-1 && M[i][1]==-1) { if (Hola[A[i]]!=-1) { M[i][1]=Hola[A[i]]; C++; } if (Hola[B[i]]!=1) { M[i][0]=Hola[B[i]]; C++; } } } if (K==C) { cout<<"DA"; return 0; } } cout<<"DA"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...