Submission #82267

# Submission time Handle Problem Language Result Execution time Memory
82267 2018-10-29T17:07:45 Z Milki Zamjena (COCI18_zamjena) C++14
70 / 70
154 ms 15944 KB
#include<bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)

typedef long long ll;
typedef pair<int, int> point;

const int MAXN = 5e4 + 5;

unordered_map<string, string> val;
unordered_map<string, vector<string> > isti;

int n;
string a[MAXN], b[MAXN];

void postavi(string x, string value){
    string realVal = val[x];
    if(realVal != ""){
        if(realVal == value) return;
        else{
            cout << "NE\n";
            exit(0);
        }
    }
    val[x] = value;
    for(auto it : isti[x]){
        postavi(it, value);
    }
    isti[x].clear();
}

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

    cin >> n;
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];

    REP(i, n){
        if(a[i] == b[i]) continue;
        if(a[i][0] >= '0' && a[i][0] <= '9' && b[i][0] >= '0' && b[i][0] <= '9'){
            if(a[i] != b[i]){
                cout << "NE\n";
                return 0;
            }
        }
        else if( (a[i][0] >= '0' && a[i][0] <= '9') || (b[i][0] >= '0' && b[i][0] <= '9')){
            if(a[i][0] >= '0' && a[i][0] <= '9') swap(a[i], b[i]);

            postavi(a[i], b[i]);
        }
        else{
            string val_a = val[a[i]], val_b = val[b[i]];
            //cout << val_a _ val_b <<" value\n";
            if(val_a == "") {
                swap(val_a, val_b);
                swap(a[i], b[i]);
            }

            if(val_a == "" && val_b == ""){
                isti[a[i]].pb(b[i]);
                isti[b[i]].pb(a[i]);
            }
            else if(val_a != "" && val_b == ""){
                postavi(b[i], val_a);
            }
            else if(val_a != val_b){
                cout << "NE\n";
                return 0;
            }
        }
    }
    cout << "DA\n";
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3448 KB Output is correct
2 Correct 5 ms 3572 KB Output is correct
3 Correct 4 ms 3572 KB Output is correct
4 Correct 4 ms 3572 KB Output is correct
5 Correct 4 ms 3592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3612 KB Output is correct
2 Correct 5 ms 3612 KB Output is correct
3 Correct 4 ms 3612 KB Output is correct
4 Correct 4 ms 3632 KB Output is correct
5 Correct 4 ms 3632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3632 KB Output is correct
2 Correct 5 ms 3632 KB Output is correct
3 Correct 4 ms 3632 KB Output is correct
4 Correct 4 ms 3632 KB Output is correct
5 Correct 5 ms 3632 KB Output is correct
6 Correct 4 ms 3632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3884 KB Output is correct
2 Correct 5 ms 3884 KB Output is correct
3 Correct 7 ms 4200 KB Output is correct
4 Correct 8 ms 4328 KB Output is correct
5 Correct 7 ms 4328 KB Output is correct
6 Correct 7 ms 4328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 5236 KB Output is correct
2 Correct 29 ms 7372 KB Output is correct
3 Correct 59 ms 9836 KB Output is correct
4 Correct 36 ms 9836 KB Output is correct
5 Correct 154 ms 15944 KB Output is correct
6 Correct 51 ms 15944 KB Output is correct