# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
158691 | InfiniteJest | Zamjena (COCI18_zamjena) | C++14 | 16 ms | 6648 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 <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#include <math.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
typedef long long ll;
int n;
vector<int> nodi[110000];
string va[50001];
string vb[50001];
int val[110000];
bool flag=1;
bool vis[110000];
int num(string s){
int tot=0;
for(int i=0;i<s.length();i++){
tot=tot*10+s[i]-48;
}
return tot;
}
void dfs(int k, int f){
vis[k]=1;
val[k]=f;
for(int i=0;i<nodi[k].size();i++){
if(!vis[nodi[k][i]]){
vis[nodi[k][i]]=1;
dfs(nodi[k][i],f);
}
}
}
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>va[i];
}
for(int i=0;i<n;i++){
cin>>vb[i];
}
for(int i=0;i<n;i++){
if(va[i][0]>='a'&&va[i][0]<='z'&&(vb[i][0]>='a'&&vb[i][0]<='z')){
nodi[i].pb(n+i);
nodi[n+i].pb(i);
}
}
for(int i=0;i<n;i++){
if(va[i][0]>='0'&&va[i][0]<='9'&&(vb[i][0]<'0'||vb[i][0]>'9')){
if(val[n+i]==0){
dfs(n+i,num(va[i]));
}
else{
if(val[n+i]!=num(va[i])){
flag=0;
break;
}
}
}
else if((va[i][0]<'0'||va[i][0]>'9')&&(vb[i][0]>='0'&&vb[i][0]<='9')){
if(val[i]==0){
dfs(i,num(vb[i]));
}
else{
if(val[i]!=num(vb[i])){
flag=0;
break;
}
}
}
else if((va[i][0]>='0'&&va[i][0]<='9')&&vb[i][0]>='0'&&vb[i][0]<='9'){
if(num(va[i])!=num(vb[i])){
flag=0;
break;
}
}
}
if(flag)cout<<"DA";
else cout<<"NE";
}
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... |