답안 #728756

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
728756 2023-04-23T03:07:30 Z Cris_MCG Zamjena (COCI18_zamjena) C++17
56 / 70
199 ms 15912 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

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

  //ifstream fin; fin.open("Copia Copia b.txt");

  int n;
  cin >> n;
  pair<string, string> p[n];
  vector<int> pos;
  queue<string> v;
  map<string, vector<string>> mapa;
  map<string, string> val;
  map<int, bool> ya;
  for(int i = 0; i < n; i++)  {
    string s;
    cin >> s;
    if(s[0] - '0' >= 1 && s[0] - '0' <= 9)  {
      p[i].first = s;
      pos.push_back(i);
      ya[i] = 1;
    }
    else
      p[i].first = s;
  }
  for(int i = 0; i < n; i++)  {
    string s;
    cin >> s;
    if(s[0] - '0' >= 1 && s[0] - '0' <= 9)  {
      p[i].second = s;
      if(!ya[i])
        pos.push_back(i);
    }
    else
      p[i].second = s;
  }
  for(int i = 0; i < n; i++)  {
    if(p[i].first[0] > 60 && p[i].second[0] > 60)  {
      mapa[p[i].first].push_back(p[i].second);
      if(p[i].first != p[i].second)
        mapa[p[i].second].push_back(p[i].first);
    }
  }
  bool b = 0;
  for(int i = 0; i < pos.size() && !b; i++)  {
    int x = pos[i];
    if(p[x].first[0] - '0' >= 1 && p[x].first[0] - '0' <= 9 && p[x].second[0] - '0' >= 0 && p[x].second[0] - '0' <= 9)  {
      if(p[x].first != p[x].second)
        b = 1;
      continue;
    }
    else if(p[x].second[0] > 60)  {
      if(val[p[x].second] == "")  {
        val[p[x].second] = p[x].first;
        v.push(p[x].second);
      }
      else
        if(val[p[x].second] != p[x].first)
          b = 1;
      continue;
    }
    else if(p[x].first[0] > 60)  {
      if(val[p[x].first] == "")  {
        val[p[x].first] = p[x].second;
        v.push(p[x].first);
      }
      else
        if(val[p[x].first] != p[x].second)
          b = 1;
      continue;
    }
  }
  if(b)  {
    cout << "NE" << '\n';
    return 0;
  }
  while(!v.empty() && !b)  {
    string aux = v.front();
    v.pop();
    string va = val[aux];
    for(int i = 0; i < mapa[aux].size(); i++)  {
      if(val[mapa[aux][i]] == "")  {
        v.push(mapa[aux][i]);
        val[mapa[aux][i]] = va;
      }
      else  {
        if(val[mapa[aux][i]] != va)
          b = 1;
      }
    }
  }
  if(!b)
    cout << "DA" << '\n';
  else
    cout << "NE" << '\n';

  return 0;
}

Compilation message

zamjena.cpp: In function 'int main()':
zamjena.cpp:50:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   for(int i = 0; i < pos.size() && !b; i++)  {
      |                  ~~^~~~~~~~~~~~
zamjena.cpp:86:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |     for(int i = 0; i < mapa[aux].size(); i++)  {
      |                    ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Incorrect 1 ms 328 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 5 ms 980 KB Output is correct
4 Correct 5 ms 980 KB Output is correct
5 Correct 6 ms 1108 KB Output is correct
6 Correct 4 ms 1092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 2388 KB Output is correct
2 Correct 48 ms 5776 KB Output is correct
3 Correct 37 ms 7536 KB Output is correct
4 Correct 51 ms 9928 KB Output is correct
5 Correct 199 ms 15912 KB Output is correct
6 Correct 148 ms 11848 KB Output is correct