# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
133281 | forelax | Cezar (COCI16_cezar) | C++14 | 3 ms | 524 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<pair<int,string> > v;
vector<vector<int> > dir(26,vector<int> (26));
bool good=true;
void attack(int b,int e,int c){
int l=e-b;
if(l<2)return;
vector<char> tht(l);
vector<bool> seen(26);
for(int i = b ; i < e ; i ++)
tht[i-b]=c<v[i].second.length()?v[i].second[c]:' ';
bool f=false;
for(int i = 0 ; i < l ; i ++){
if(tht[i]!=' ')f=true;
else{
if(f){
good=false;
return;
}
}
}
for(int i = l-1,j ; i >= 0 ; ){
j=i;
while(j>=0&&tht[j]==tht[i])
j--;
if(tht[i]!=' '){
int ch=tht[i]-'a';
if(seen[ch]){
good=false;
return;
}
for(int k = 0 ; k < 26 ; k ++){
if(seen[k]){
if(dir[k][ch]){
good=false;
return;
}
dir[ch][k]=true;
}
}
attack(b+j+1,b+i+1,c+1);
seen[tht[i]-'a']=true;
}
i=j;
}
}
vector<int> visited(26);
vector<int> visiting(26);
vector<int> rez;
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);
}
}
rez.push_back(ind);
visited[ind]=true;
}
int main(){
cin>>n;
v.resize(n);
for(int i = 0 ; i < n ; i ++){
cin>>v[i].second;
}
for(int j = 0 ; j < n ; j ++){
cin>>v[j].first;
}
sort(v.begin(),v.end());
attack(0,n,0);
if(!good){
cout<<"NE";
return 0;
}
for(int i = 26 ; i >= 0 ; i --){
if(!visited[i]){
dfs(i);
}
}
if(!good){
cout<<"NE";
return 0;
}
cout<<"DA"<<endl;
vector<char> ord(26);
for(int i = 0 ; i < rez.size() ; i ++){
ord[rez[i]]=char('a'+25-i);
}
for(int i = 0 ; i < 26 ; i ++)cout<<ord[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... |