# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
472620 | 2021-09-13T20:48:23 Z | MamdouhN | Zamjena (COCI18_zamjena) | C++17 | 23 ms | 8780 KB |
#include<bits/stdc++.h> using namespace std; #define int long long vector<int> a; vector<int> b; bool isNumeric(string s){ for(int i=0;i<s.size();i++){ if(s[i]<'0'||s[i]>'9')return false; } return true; } int dsu[1000000]; int findIt(int x){ if(x==dsu[x])return x; return dsu[x] = findIt(dsu[x]); } void unionIt(int x,int y){ dsu[findIt(x)] = findIt(y); } map<string,int> variableMapper; main() { for(int i=0;i<1000000;i++)dsu[i]=i; int n; cin>>n; int cnt = 1; for(int i=0;i<n;i++){ string s; cin>>s; if(isNumeric(s))a.push_back(stoi(s)); else{ if(variableMapper[s]==0){ variableMapper[s] = 1000+cnt; cnt++; } a.push_back(variableMapper[s]); } } for(int i=0;i<n;i++){ string s; cin>>s; if(isNumeric(s))b.push_back(stoi(s)); else{ if(variableMapper[s]==0){ variableMapper[s] = 1000+cnt; cnt++; } b.push_back(variableMapper[s]); } } bool failure = false; for(int i=0;i<n;i++){ if(failure)break; if(a[i]<=1000&&b[i]<=1000){ if(a[i]!=b[i])failure = true; continue; } if(a[i]>1000&&b[i]<=1000){ if(findIt(a[i])<=1000 && findIt(a[i])!= b[i]) failure = true; unionIt(a[i],b[i]); continue; } if(a[i]<=1000&&b[i]>1000){ if(findIt(b[i])<=1000 && findIt(b[i])!= a[i]) failure = true; unionIt(b[i],a[i]); continue; } if(findIt(a[i])<=1000 && findIt(b[i])<=1000 && findIt(a[i])!=findIt(b[i]) ){ failure = true; continue; } if(findIt(b[i])<=1000){ unionIt(b[i],a[i]); continue; } unionIt(a[i],b[i]); } if(failure)cout<<"NE"<<endl; else cout<<"DA"<<endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 8012 KB | Output is correct |
2 | Correct | 4 ms | 8012 KB | Output is correct |
3 | Correct | 4 ms | 8012 KB | Output is correct |
4 | Correct | 4 ms | 8012 KB | Output is correct |
5 | Correct | 4 ms | 8012 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 8064 KB | Output is correct |
2 | Correct | 4 ms | 8012 KB | Output is correct |
3 | Correct | 4 ms | 8012 KB | Output is correct |
4 | Correct | 6 ms | 8012 KB | Output is correct |
5 | Correct | 5 ms | 8012 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 8012 KB | Output is correct |
2 | Correct | 4 ms | 8012 KB | Output is correct |
3 | Correct | 4 ms | 8012 KB | Output is correct |
4 | Correct | 5 ms | 8012 KB | Output is correct |
5 | Correct | 5 ms | 8012 KB | Output is correct |
6 | Incorrect | 5 ms | 8116 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 8140 KB | Output is correct |
2 | Correct | 5 ms | 8140 KB | Output is correct |
3 | Incorrect | 8 ms | 8268 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 23 ms | 8780 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |