# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
133305 |
2019-07-20T11:42:06 Z |
forelax |
Cezar (COCI16_cezar) |
C++14 |
|
4 ms |
380 KB |
#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 ; i ++){
for(int j = i+1 ; j < n ; j ++){
int ml=min(s[i].length(),s[j].length());
if(s[i].substr(0,ml)==s[j].substr(0,ml)){
if(s[j].length()<s[i].length()){
cout<<"NE";
return 0;
}else continue;
}
for(int k = 0 ; k < ml ; k ++){
if(s[i][k]==s[j][k])continue;
else{
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;
}
}
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];
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
292 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |