Submission #166417

# Submission time Handle Problem Language Result Execution time Memory
166417 2019-12-02T09:56:40 Z tincamatei Zamjena (COCI18_zamjena) C++14
14 / 70
22 ms 5048 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 50000;

string a[MAX_N], b[MAX_N];
map<string, vector<string> > graph;
map<string, int> vartable;
map<string, bool> viz;
bool ok = true;

int getVal(string str) {
  if(!viz[str]) {
    viz[str] = true;
    int finalVal = -1;
    if(vartable.count(str) > 0)
      finalVal = vartable[str];
    vartable[str] = -1;
    for(auto it: graph[str]) {
      if(finalVal == -1)
        finalVal = getVal(str);
      else {
        int val2 = getVal(str);
        if(val2 != finalVal)
          ok = false;
      }
    }

    vartable[str] = finalVal;
  }
  return vartable[str];
}

int main() {
  int N;
  bool ok = true;
  cin >> N;
  for(int i = 0; i < N; ++i)
    cin >> a[i];
  for(int i = 0; i < N; ++i)
    cin >> b[i];

  for(int i = 0; i < N; ++i) {
    if(isalpha(a[i][0]) && isalpha(b[i][0])) {
      if(a != b) {
        graph[a[i]].push_back(b[i]);
        graph[b[i]].push_back(a[i]);
      }
    } else if(isalpha(a[i][0])) {
      int valB = atoi(b[i].c_str());
      if(vartable.count(a[i]) > 0 && vartable[a[i]] != valB)
        ok = false;
      else {
        vartable[b[i]] = valB;
      }
    } else if(isalpha(b[i][0])) {
      int valA = atoi(a[i].c_str());
      if(vartable.count(b[i]) > 0 && vartable[b[i]] != valA)
        ok = false;
      else
        vartable[b[i]] = valA;
    } else if(atoi(a[i].c_str()) != atoi(b[i].c_str()))
      ok = false;
  }

  for(auto it: vartable)
    getVal(it.first);

  if(ok)
    printf("DA");
  else
    printf("NE");

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3448 KB Output is correct
2 Correct 5 ms 3448 KB Output is correct
3 Correct 4 ms 3448 KB Output is correct
4 Correct 5 ms 3420 KB Output is correct
5 Correct 5 ms 3448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3448 KB Output is correct
2 Incorrect 5 ms 3448 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3420 KB Output is correct
2 Correct 5 ms 3448 KB Output is correct
3 Correct 5 ms 3448 KB Output is correct
4 Incorrect 5 ms 3448 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3576 KB Output is correct
2 Correct 6 ms 3576 KB Output is correct
3 Incorrect 10 ms 3880 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 5048 KB Output isn't correct
2 Halted 0 ms 0 KB -