# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
133292 | forelax | Cezar (COCI16_cezar) | C++14 | 3 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;
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-1 ; i ++){
int ml=min(s[i].length(),s[i+1].length());
if(s[i].substr(0,ml)==s[i+1].substr(0,ml)){
if(s[i+1].length()<s[i].length()){
cout<<"NE";
return 0;
}else continue;
}
for(int j = 0 ; j < s[i].length() && j<s[i+1].length() ; j ++){
if(s[i][j]==s[i+1][j])continue;
else{
dir[s[i][j]-'a'][s[i+1][j]-'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];
}
}
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... |