Submission #555350

#TimeUsernameProblemLanguageResultExecution timeMemory
555350new_accZamjena (COCI18_zamjena)C++14
70 / 70
24 ms3948 KiB
#include<bits/stdc++.h> #define fi first #define se second #define pitem item* using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; const int N=1e6+10; const int SS=1<<19; const int INFi=2e9; const ll INFl=1e13; const ll mod2=998244353; const ll mod=1e9+7; const ll mod3=1000696969; const ll p=70032301; const ull p2=913; const int L=20; int fau[N],akt[N]; ll t[N],t2[N]; bool b1[N],b2[N]; unordered_map<int,int>m; int Find(int a){ if(fau[a]==a) return a; return fau[a]=Find(fau[a]); } void Union(int a,int b){ fau[Find(a)]=Find(fau[b]); } void solve(){ int n; cin>>n; int l=0; for(int i=1;i<=n;i++){ string s; cin>>s; if(int(s[0])>=48 and int(s[0])<=57){ int curr=0; for(int j=0;j<s.size();j++) curr=curr*10+(s[j])-48; t[i]=curr; b1[i]=1; continue; } ll akth=0; for(int j=0;j<s.size();j++){ akth=akth*p+int(s[j]); akth%=mod; } if(!m[akth]) m[akth]=++l; t[i]=akth; } for(int i=1;i<=n;i++){ string s; cin>>s; if(int(s[0])>=48 and int(s[0])<=57){ int curr=0; for(int j=0;j<s.size();j++) curr=curr*10+(s[j])-48; t2[i]=curr; b2[i]=1; continue; } ll akth=0; for(int j=0;j<s.size();j++){ akth=akth*p+int(s[j]); akth%=mod; } if(!m[akth]) m[akth]=++l; t2[i]=akth; } for(int i=1;i<=l;i++) fau[i]=i; for(int i=1;i<=n;i++) if(!b1[i] and !b2[i]) Union(m[t[i]],m[t2[i]]); bool res=1; for(int i=1;i<=n;i++){ if(!b1[i] and !b2[i]) continue; if(b1[i] and b2[i]){ if(t[i]!=t2[i]) res=0; continue; } if(b1[i]){ int pom=Find(m[t2[i]]); if(!akt[pom]) akt[pom]=t[i]; if(akt[pom]!=t[i]) res=0; }else{ int pom=Find(m[t[i]]); if(!akt[pom]) akt[pom]=t2[i]; if(akt[pom]!=t2[i]) res=0; } } cout<<(res?"DA":"NE")<<"\n"; } int main(){ ios_base::sync_with_stdio(0),cin.tie(0); int tt=1; while(tt--) solve(); }

Compilation message (stderr)

zamjena.cpp: In function 'void solve()':
zamjena.cpp:40:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |             for(int j=0;j<s.size();j++) curr=curr*10+(s[j])-48;
      |                         ~^~~~~~~~~
zamjena.cpp:46:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for(int j=0;j<s.size();j++){
      |                     ~^~~~~~~~~
zamjena.cpp:58:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |             for(int j=0;j<s.size();j++) curr=curr*10+(s[j])-48;
      |                         ~^~~~~~~~~
zamjena.cpp:64:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         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...