Submission #133305

#TimeUsernameProblemLanguageResultExecution timeMemory
133305forelaxCezar (COCI16_cezar)C++14
40 / 100
4 ms380 KiB
#include<bits/stdc++.h> using namespace std; int n; vector<string> s,v; vector<vector<int> > dir(26,vector<int> (26)); bool good=true; vector<int> visiting(26); vector<int> visited(26); vector<int> ord; 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]){ dfs(i); if(!good)return; } } ord.push_back(ind); visited[ind]=true; } int main(){ cin>>n; v.resize(n); s.resize(n); for(int i = 0 ; i < n ; i ++) cin>>v[i]; for(int i = 0,a ; i < n ; i ++){ cin>>a; a--; s[i]=v[a]; } for(int i = 0 ; i < n ; i ++){ for(int j = i+1 ; j < n ; j ++){ int ml=min(s[i].length(),s[j].length()); if(s[i].substr(0,ml)==s[j].substr(0,ml)){ if(s[j].length()<s[i].length()){ cout<<"NE"; return 0; }else continue; } for(int k = 0 ; k < ml ; k ++){ if(s[i][k]==s[j][k])continue; else{ dir[s[i][k]-'a'][s[j][k]-'a']=true; break; } } } } for(int i = 25 ; i>=0 ; i -- ){ if(!visited[i]) dfs(i); if(!good){ cout<<"NE"; return 0; } } reverse(ord.begin(),ord.end()); vector<char> rez(26); for(int i = 0 ; i < 26 ; i ++){ rez[ord[i]]=char('a'+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...