# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
133322 | forelax | Cezar (COCI16_cezar) | C++14 | 4 ms | 504 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
bool good=true;
vector<vector<bool> > dir(26,vector<bool> (26));
vector<bool> visited(26);
vector<bool> visiting(26);
vector<int> ord;
void dfs(int i){
if(visiting[i]){
good=false;
return;
}
visiting[i]=true;
for(int j = 0 ; j < 26 ; j ++){
if(dir[i][j]&&!visited[j]){
dfs(j);
if(!good)return;
}
}
ord.push_back(i);
visited[i]=true;
}
int main(){
int n;
cin>>n;
vector<string> g(n),s(n);
for(int i = 0 ; i < n ; i ++)cin>>g[i];
for(int i = 0,j ; i < n ; i ++){
cin>>j;
s[i]=g[j-1];
}
for(int i = 0 ; i < n ; i ++){
for(int j = i+1 ; j < n ; j ++){
for(int k = 0 ; true ; k ++){
if(k>s[i].length())break;
if(k>s[j].length()){
cout<<"NE";
return 0;
}
if(s[i][k]==s[j][k])continue;
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;
}
}
}
cout<<"DA"<<endl;
vector<char> rez(26);
reverse(ord.begin(),ord.end());
for(int i = 0 ; i < 26 ; i ++){
rez[ord[i]]=char('a'+i);
}
for(int i = 0 ; i < rez.size() ; i ++)cout<<rez[i];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |