Submission #464654

#TimeUsernameProblemLanguageResultExecution timeMemory
464654sobaZamjena (COCI18_zamjena)C++14
70 / 70
113 ms5124 KiB
#include <bits/stdc++.h> using namespace std; const int N = 200000+5; int n ,k , sol; int fat[N]; int fin(int x) { if(fat[x]!=x) return fat[x] = fin(fat[x]); return x; } void unio(int a , int b) { int aa = fin(a); int bb = fin(b); if(aa!=bb) { fat[aa] = bb; } else sol++; } int toint(string s) { int x=0; for(int i = 0 ; i <s.size(); i++) { x*=10; x+=(s[i]-'0'); } return x; } int main() { cin>>n; for(int i = 0;i<N;i++) fat[i] = i; map<string,int>mp; string a , b; int x , y; vector<int>v1,v2; int flag=1; int cnt=1001; for(int i = 0;i<n;i++){ cin>>a; flag=1; for(int j = 0 ; j < a.size() ;j++) { if(a[j]>'9'||a[j]<'0') flag=0; } if(flag) x=toint(a); else { if(mp[a]==0) { mp[a]=cnt++; } x=mp[a]; } v1.push_back(x); } for(int i = 0;i<n;i++){ cin>>a; flag=1; for(int j = 0 ; j < a.size() ;j++) { if(a[j]>'9'||a[j]<'0') flag=0; } if(flag) x=toint(a); else { if(mp[a]==0) { mp[a]=cnt++; } x=mp[a]; } //cout << v1[i] << " " << x << "\n"; unio(x , v1[i]); } flag=1; for(int i = 0 ; i<=1000 ; i++) { for(int j = 0 ; j<= 1000 ; j++) { if(i==j)continue; x=fin(i); y=fin(j); if(x==y) { flag=0; break; } } if(!flag)break; } if(!flag) { cout << "NE"; return 0; } cout << "DA"; return 0; }

Compilation message (stderr)

zamjena.cpp: In function 'int toint(std::string)':
zamjena.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i = 0 ; i <s.size(); i++)
      |                     ~~^~~~~~~~~
zamjena.cpp: In function 'int main()':
zamjena.cpp:51:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for(int j = 0 ; j  < a.size() ;j++)
      |                         ~~~^~~~~~~~~~
zamjena.cpp:71:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for(int j = 0 ; j  < a.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...