Submission #721413

# Submission time Handle Problem Language Result Execution time Memory
721413 2023-04-10T20:45:09 Z vjudge1 Zamjena (COCI18_zamjena) C++17
28 / 70
25 ms 2556 KB
#include <bits/stdc++.h>
#define sts stable_sort
#define B begin()
#define rB rbegin()
#define E end()
#define rE rend()
#define F first
#define S second
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define eb emplace_back
#define ll long long
#define ui unsigned int
#define ull unsigned long long

using namespace std;

const int MAXN = 1e6 + 4;
const int MOD = 1e9 + 7;
map<string, int> m;
vector<pair<string, string> > aux;

int to_int(string s){
    int n = 0;

    for(int i = 0; i < s.size(); i++){
        n *= 10;
        n += s[i] - '0';
    }

    return n;
}

bool comp(string s){
    if(s[0] == 'a' || s[0] == 'b' || s[0] == 'c' || s[0] == 'd' || s[0] == 'e' || s[0] == 'f' || s[0] == 'g' || s[0] == 'h' || s[0] == 'i' || s[0] == 'j' || s[0] == 'k' || s[0] == 'l' || s[0] == 'm' || s[0] == 'n' || s[0] == 'o' || s[0] == 'p' || s[0] == 'q' || s[0] == 'r' || s[0] == 's' || s[0] == 't' || s[0] == 'u' || s[0] == 'v' || s[0] == 'w' || s[0] == 'x' || s[0] == 'y' || s[0] == 'z'){
        return 1;
    }else{
        return 0;
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    int n; cin >> n;

    vector<pair<string, string> > v(n);

    for(int i = 0; i < n; i++){
        cin >> v[i].F; m[v[i].F] = -1;
    }
    for(int i = 0; i < n; i++){
        cin >> v[i].S; m[v[i].S] = -1;
    }
    bool a = 1;
    for(int i = 0; i < n; i++){
        if(v[i].F == v[i].S)continue;
        if(v[i].F != v[i].S){
            if(comp(v[i].F) && !comp(v[i].S)){
                if(m[v[i].F] != -1 && m[v[i].F] != to_int(v[i].S)){
                    a = 0; break;
                }
                m[v[i].F] = to_int(v[i].S);
            }else if(comp(v[i].S) && !comp(v[i].F)){
                if(m[v[i].S] != -1 && m[v[i].S] != to_int(v[i].F)){
                    a = 0; break;
                }
                m[v[i].S] = to_int(v[i].F);
            }else if(comp(v[i].S) && comp(v[i].F)){
                if(m[v[i].F] == m[v[i].S] == -1){
                    continue;
                }else if(m[v[i].F] == -1 && m[v[i].S] != -1){
                    m[v[i].F] = m[v[i].S];
                }else if(m[v[i].S] == -1 && m[v[i].F] != -1){
                    m[v[i].S] = m[v[i].F];
                }else if(m[v[i].S] != m[v[i].S] && m[v[i].F] != -1 && m[v[i].S] != -1){
                    a = 0; break;
                }
            }else if(!comp(v[i].S) && !comp(v[i].F)){
                a = 0; break;
            }
        }
        aux.pb({v[i].F, v[i].S});
    }
    if(!a){
        cout << "NE\n";
        return 0;
    }
    for(auto &c : aux){
        if(comp(c.F) && comp(c.S)){
            if(m[c.F] == m[c.S] && m[c.F] != -1){
                continue;
            }else if(m[c.F] == -1 || m[c.S] == -1){
                continue;
            }else{
                a = 0;break;
            }
        }else if(!comp(c.F)){
            if(to_int(c.F) == m[c.S]){
                continue;
            }else if(m[c.S] == -1){
                continue;
            }else if(to_int(c.F) != m[c.S]){
                a = 0; break;
            }
        }else if(!comp(c.S)){
            if(to_int(c.S) == m[c.F]){
                continue;
            }else if(m[c.F] == -1){
                continue;
            }else if(to_int(c.S) != m[c.F]){
                a = 0; break;
            }
        }
    }
    if(a){
        cout << "DA\n";
    }else{
        cout << "NE\n";
    }

    return 0;
}

Compilation message

zamjena.cpp: In function 'int to_int(std::string)':
zamjena.cpp:28:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
zamjena.cpp: In function 'int main()':
zamjena.cpp:73:43: warning: comparison of constant '-1' with boolean expression is always false [-Wbool-compare]
   73 |                 if(m[v[i].F] == m[v[i].S] == -1){
zamjena.cpp:73:30: warning: suggest parentheses around comparison in operand of '==' [-Wparentheses]
   73 |                 if(m[v[i].F] == m[v[i].S] == -1){
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 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 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 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
6 Incorrect 1 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Incorrect 7 ms 1044 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 2556 KB Output isn't correct
2 Halted 0 ms 0 KB -