# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
133390 | forelax | Cezar (COCI16_cezar) | C++14 | 4 ms | 376 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;
vector<int> visited(26),visiting(26),order;
vector<vector<int> > dir(26,vector<int> (26));
bool good=true;
void dfs(int ind){
for(int i = 0 ; i < 26 ; i ++){
if(visited[i]||!dir[ind][i])continue;
if(visiting[i]){
good=false;
return;
}
visiting[i]=true;
dfs(i);
if(!good)return;
}
order.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];
}
// cout<<endl;
for(int i = 0,t ; i < n ; i ++){
cin>>t;t--;
b[i]=a[t];
// cout<<b[i]<<endl;
}
for(int i = 0,k ; i < n ; i ++){
for(int j = i+1 ; j < n ; j ++){
int l=min(b[i].length(),b[j].length());
for( k=0 ; k<l ; k ++)
if(b[i][k]!=b[j][k])break;
if(k==b[j].length()){
cout<<"NE";
return 0;
}
if(k==b[i].length()){
continue;
}
dir[b[i][k]-'a'][b[j][k]-'a']=true;
}
}
for(int i = 25 ; i >= 0 ; i --){
if(visited[i])continue;
visiting[i]=true;
dfs(i);
if(!good){
cout<<"NE";
return 0;
}
}
vector<char> rez(26);
for(int i = 0 ; i < order.size() ; i ++)
rez[order[i]]=char('z'-i);
cout<<"DA"<<endl;
// for(int i = 0 ; i < 26 ; i ++)
// cout<<char(i+'a');
// cout<<endl;
for(int i = 0 ; i < 26 ; 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... |