Submission #471489

# Submission time Handle Problem Language Result Execution time Memory
471489 2021-09-09T13:37:02 Z HossamHero7 Zamjena (COCI18_zamjena) C++14
70 / 70
212 ms 16080 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define endl '\n'
map <string,vector<string>> adj;
map <string,bool> vis;
string curNum = "-1";
bool isNum(string s){
    for(auto i : s){
        if(i < '0' || i > '9') return 0;
    }
    return 1;
}
bool valid = 1;
void dfs(string node){
    vis[node] = 1;
    if(isNum(node) && curNum == "-1"){
        curNum = node;
    }
    for(auto ch : adj[node]){
        if(!isNum(ch) || curNum == ch || curNum == "-1"){
            if(!vis[ch]) dfs(ch);
        }
        else valid = 0;
    }
}
void solve(){
    int n;
    cin>>n;
    vector <string> v1(n);
    vector <string> v2(n);
    for(auto &i:v1) cin>>i;
    for(auto &i:v2) cin>>i;
    for(int i=0;i<n;i++){
        adj[v1[i]].push_back(v2[i]);
        adj[v2[i]].push_back(v1[i]);
    }
    for(auto i : v1){
        if(!vis[i]) dfs(i);
        if(!valid){
            cout<<"NE"<<endl;
            return;
        }
        valid = 1;
        curNum = "-1";
    }
    for(auto i : v2){
        if(!vis[i]) dfs(i);
        if(!valid){
            cout<<"NE"<<endl;
            return;
        }
        curNum = "-1";
    }
    cout<<"DA"<<endl;
}
int main()
{
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 248 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 548 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 4 ms 972 KB Output is correct
4 Correct 5 ms 1100 KB Output is correct
5 Correct 9 ms 1228 KB Output is correct
6 Correct 6 ms 1068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 3280 KB Output is correct
2 Correct 57 ms 5888 KB Output is correct
3 Correct 50 ms 7732 KB Output is correct
4 Correct 79 ms 10228 KB Output is correct
5 Correct 212 ms 16080 KB Output is correct
6 Correct 155 ms 12100 KB Output is correct