Submission #637540

# Submission time Handle Problem Language Result Execution time Memory
637540 2022-09-02T11:57:34 Z NotLinux Zamjena (COCI18_zamjena) C++14
28 / 70
6 ms 1956 KB
/**
 * author: NotLinux
 * created: 02.09.2022 ~ 14:19:34
**/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#ifdef LOCAL
    #include "/home/notlinux/debug.h"
#else
    #define debug(x...) void(37)
#endif
#define sos(x) dict.find(fond(x)) != dict.end()
int n;
map < string , string > par;
map < string , string > mpa;
string fond(string str){
    if(par[str] == str)return str;
    if(mpa.find(str) == mpa.end()){
        par[str] = str;
        mpa[str] = 1;
    }
    par[str] = fond(par[str]);
    return par[str];
}
void merge(string a , string b){
    par[fond(a)] = fond(b);
}
bool nuum(string str){
    for(auto itr : str)if(itr < '0' or itr > '9')return 0;
    return 1;
}
void solve(){
    cin >> n;
    vector < string > a(n)  ,b(n);
    map < string , int > dict;
    for(auto &inp : a)cin >> inp;
    for(auto &inp : b)cin >> inp;
    for(int i = 0;i<n;i++){
        if(a[i] == b[i])continue;
        if(nuum(a[i]) and nuum(b[i])){
            cout << "NE" << endl;
            return;
        }
        else if(nuum(a[i]) and nuum(b[i])==0){
            if(sos(b[i])==0){
                dict[fond(b[i])] = stoi(a[i]);
            }
            if(dict[fond(b[i])] != stoi(a[i])){
                cout << "NE" << endl;
                return;   
            }
        }
        else if(nuum(a[i])==0 and nuum(b[i])){
            if(sos(a[i])==0){
                dict[fond(a[i])] = stoi(b[i]);
            }
            if(dict[fond(a[i])] != stoi(b[i])){
                cout << "NE" << endl;
                return;   
            }
        }
        else {
            if((sos(a[i])==0 and sos(b[i])==0) and (dict[a[i]] != dict[b[i]])){
                cout << "NE" << endl;
                return;
            }
                merge(a[i],b[i]);
        }
    }
    cout << "DA" << endl;
}
int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    int tt=1;
    //cin >> tt;
    while(tt--)solve();
}

Compilation message

zamjena.cpp: In function 'void solve()':
zamjena.cpp:13:35: warning: suggest parentheses around comparison in operand of '==' [-Wparentheses]
   13 | #define sos(x) dict.find(fond(x)) != dict.end()
      |                ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
zamjena.cpp:46:16: note: in expansion of macro 'sos'
   46 |             if(sos(b[i])==0){
      |                ^~~
zamjena.cpp:13:35: warning: suggest parentheses around comparison in operand of '==' [-Wparentheses]
   13 | #define sos(x) dict.find(fond(x)) != dict.end()
      |                ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
zamjena.cpp:55:16: note: in expansion of macro 'sos'
   55 |             if(sos(a[i])==0){
      |                ^~~
zamjena.cpp:13:35: warning: suggest parentheses around comparison in operand of '==' [-Wparentheses]
   13 | #define sos(x) dict.find(fond(x)) != dict.end()
      |                ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
zamjena.cpp:64:17: note: in expansion of macro 'sos'
   64 |             if((sos(a[i])==0 and sos(b[i])==0) and (dict[a[i]] != dict[b[i]])){
      |                 ^~~
zamjena.cpp:13:35: warning: suggest parentheses around comparison in operand of '==' [-Wparentheses]
   13 | #define sos(x) dict.find(fond(x)) != dict.end()
      |                ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
zamjena.cpp:64:34: note: in expansion of macro 'sos'
   64 |             if((sos(a[i])==0 and sos(b[i])==0) and (dict[a[i]] != dict[b[i]])){
      |                                  ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1492 KB Output is correct
2 Incorrect 6 ms 1956 KB Output isn't correct
3 Halted 0 ms 0 KB -