#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 340
#define mid (l+r)/2
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=1e18*4;
const ld pai=acos(-1);
int n;
string s[109],ss[109];
vi v[29];
int done[29],deg[29],ans[29],yes[29];
void dfs(int node){
done[node]=1;
for(auto u:v[node]){
if(done[u]==2)C;
if(done[u]==1)cout<<"NE"<<endl,exit(0);
dfs(u);
}
done[node]=2;
}
void make(string a,string b){
int z=0;
for(int i=0;i<min((int) a.size(),(int) b.size());i++){
if(a[i]==b[i])C;
z=1;
v[a[i]-'a'].pb(b[i]-'a');
deg[b[i]-'a']++;
break;
}
}
int pre(string x,string xx){
if(x.size()>xx.size())return 0;
int z=0;
for(int i=0;i<x.size();i++){
if(x[i]!=xx[i])z=1;
}
return !z;
}
int main(){
cin>>n;
for(int i=0;i<n;i++)cin>>ss[i];
for(int i=0;i<n;i++){
int x;cin>>x;
x--;
s[i]=ss[x];
}
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
if(pre(s[j],s[i])){
cout<<"NE"<<endl;
exit(0);
}
}
}
for(int i=0;i<n-1;i++){
if(pre(s[i],s[i+1]))C;
make(s[i],s[i+1]);
}
for(int i=0;i<26;i++){
if(done[i]==0)dfs(i);
}
queue<int>q;
for(int i=0;i<26;i++)
if(deg[i]==0)q.push(i),yes[i]=1;
int last=(int) 'a';
while(q.size()){
int node=q.front();q.pop();
ans[node]=last++;
for(auto u:v[node]){
if(yes[u])C;
deg[u]--;
if(deg[u]==0)q.push(u),yes[u]=1;
}
}
cout<<"DA"<<endl;
for(int i=0;i<26;i++)cout<<(char)ans[i];
cout<<endl;
}
Compilation message
cezar.cpp: In function 'void make(std::__cxx11::string, std::__cxx11::string)':
cezar.cpp:43:17: warning: variable 'z' set but not used [-Wunused-but-set-variable]
int z=0;
^
cezar.cpp: In function 'int pre(std::__cxx11::string, std::__cxx11::string)':
cezar.cpp:55:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<x.size();i++){
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
348 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 |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
2 ms |
256 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 |
Incorrect |
2 ms |
296 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 |
404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |