Submission #133370

#TimeUsernameProblemLanguageResultExecution timeMemory
133370forelaxCezar (COCI16_cezar)C++14
10 / 100
3 ms504 KiB
#include<bits/stdc++.h> using namespace std; vector<vector<int> > dir(26,vector<int> (26)); vector<int> visiting(26); vector<int> visited(26); vector<int> ord; bool good=true; void dfs(int ind){ if(visiting[ind]){ good=false; return; } visiting[ind]=true; for(int i = 0 ; i < 26 ; i ++){ if(!dir[ind][i]||visited[i])continue; dfs(i); if(!good)return; } ord.push_back(ind); visited[ind]=true; } int main(){ int n; cin>>n; vector<string> a(n),b(n); for(int i = 0 ; i < n ; i ++)cin>>a[i]; for(int j = 0 , x ; j < n ; j ++){ cin>>x;x--; b[j]=a[x]; } for(int i = 0 ; i < n ; i ++){ for(int j = i+1 ; j < n ; j ++){ int ns=min(b[i].size(),b[j].size()); if(b[i].substr(0,ns)==b[j].substr(0,ns)){ if(b[i].size()<b[j].size()) continue; else{ cout<<"NE"; return 0; } } if(j!=i+1)continue; for(int k = 0 ; k < ns ; k ++){ if(b[i][k]==b[j][k])continue; dir[b[i][k]-'a'][b[j][k]-'a']=true; break; } } } for(int i = 0 ; i < 26 ; i ++){ if(visited[i])continue; dfs(i); if(!good){ cout<<"NE"; return 0; } } vector<char> rez(26); for(int i = 25 ; i >= 0 ; i --){ rez[ord[i]]=char('a'+25-i); } cout<<"DA"<<endl; for(int i = 0 ; i < 26 ; i ++) cout<<rez[i]; }
#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...
#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...