# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
133380 | forelax | Cezar (COCI16_cezar) | C++14 | 4 ms | 496 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 pref(string a,string b){
int sm=min(a.length(),b.length());
string acut=a.substr(0,sm);
string bcut=b.substr(0,sm);
if(acut==bcut&&a.length()<b.length())return true;
return false;
}
vector<vector<int> > ng(26);
bool good=true;
vector<int> visited(26);
vector<int> visiting(26);
vector<int> ord;
void dfs(int a){
if(visiting[a]){
good=false;
return;
}
visiting[a]=true;
for(int i = 0 ; i < ng[a].size() ; i ++){
int b=ng[a][i];
if(visited[b])continue;
dfs(b);
if(!good)return;
}
ord.push_back(a);
visited[a]=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 i = 0 , j; i < n ; i ++){
cin>>j;j--;
b[i]=a[j];
}
for(int i = 0 ; i < n ; i ++){
for(int j = 0 ; j < i ; j ++){
if(pref(b[i],b[j])){
cout<<"NE";
return 0;
}
}
}
for(int i = 0 ; i < n-1 ; i ++){
int j = i+1;
if(pref(b[i],b[j]))continue;
for(int k = 0 ; true ; k ++){
if(b[i][k]!=b[j][k]){
ng[b[i][k]-'a'].push_back(b[j][k]-'a');
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 = 0 ; i <ord.size() ; i ++){
rez[ord[i]]=char('z'-i);
}
cout<<"DA"<<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... |