Submission #472235

# Submission time Handle Problem Language Result Execution time Memory
472235 2021-09-13T10:02:41 Z HossamHero7 Zamjena (COCI18_zamjena) C++14
70 / 70
201 ms 15520 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 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 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 0 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 0 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 588 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 5 ms 972 KB Output is correct
4 Correct 5 ms 1100 KB Output is correct
5 Correct 8 ms 1188 KB Output is correct
6 Correct 6 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 3140 KB Output is correct
2 Correct 61 ms 5676 KB Output is correct
3 Correct 53 ms 7620 KB Output is correct
4 Correct 83 ms 9964 KB Output is correct
5 Correct 201 ms 15520 KB Output is correct
6 Correct 146 ms 11688 KB Output is correct