Submission #798378

#TimeUsernameProblemLanguageResultExecution timeMemory
798378AndiRZamjena (COCI18_zamjena)C++14
70 / 70
32 ms8420 KiB
#include <iostream> #include <unordered_map> #include <vector> using namespace std; const int Nmax=50000; int n, ind, sol[Nmax*2]; string v[Nmax]; unordered_map <long long, int> m; vector <int> ad[Nmax*2]; bool ok=1; void dfs (int nod, int val){ if (sol[nod]==0){ sol[nod]=val; for (int i=0; i<ad[nod].size(); i++) dfs(ad[nod][i], val); } else if (sol[nod]!=val) ok=0; } void eq (string &s, int val){ long long h=0; for (int i=0; i<s.size(); i++) h=h*26+s[i]-'a'+1; if (m.count(h)==0) m[h]=ind++; dfs(m[h], val+1); } void check (string &s1, string &s2){ long long h1=0, h2=0; for (int i=0; i<s1.size(); i++) h1=h1*26+s1[i]-'a'+1; for (int i=0; i<s2.size(); i++) h2=h2*26+s2[i]-'a'+1; if (m.count(h1)==0) m[h1]=ind++; if (m.count(h2)==0) m[h2]=ind++; if (sol[m[h1]]!=0 && sol[m[h2]]!=0 && sol[m[h1]]!=sol[m[h2]]) ok=0; else if (sol[m[h1]]==0 && sol[m[h2]]!=0) dfs(m[h1], sol[m[h2]]); else if (sol[m[h2]]==0 && sol[m[h1]]!=0) dfs(m[h2], sol[m[h1]]); ad[m[h1]].push_back(m[h2]); ad[m[h2]].push_back(m[h1]); } int main() { cin>>n; for (int i=0; i<n; i++) cin>>v[i]; string s; for (int i=0; i<n && ok; i++){ cin>>s; int v1=-1, v2=-1; if (v[i][0]<='9'){ v1=0; for (int j=0; j<v[i].size(); j++) v1=v1*10+v[i][j]-'0'; } if (s[0]<='9'){ v2=0; for (int j=0; j<s.size(); j++) v2=v2*10+s[j]-'0'; } if (v1!=-1 && v2!=-1 && v1!=v2) ok=0; else if (v1!=v2){ if (v1==-1) eq(v[i], v2); else eq(s, v1); } else if (v1==-1) check(v[i], s); } if (ok) cout<<"DA"; else cout<<"NE"; return 0; }

Compilation message (stderr)

zamjena.cpp: In function 'void dfs(int, int)':
zamjena.cpp:17:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |         for (int i=0; i<ad[nod].size(); i++)
      |                       ~^~~~~~~~~~~~~~~
zamjena.cpp: In function 'void eq(std::string&, int)':
zamjena.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int i=0; i<s.size(); i++)
      |                   ~^~~~~~~~~
zamjena.cpp: In function 'void check(std::string&, std::string&)':
zamjena.cpp:33:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (int i=0; i<s1.size(); i++)
      |                   ~^~~~~~~~~~
zamjena.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for (int i=0; i<s2.size(); i++)
      |                   ~^~~~~~~~~~
zamjena.cpp: In function 'int main()':
zamjena.cpp:61:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |             for (int j=0; j<v[i].size(); j++)
      |                           ~^~~~~~~~~~~~
zamjena.cpp:66:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |             for (int j=0; j<s.size(); j++)
      |                           ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...