# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
170483 | 2019-12-25T11:57:54 Z | mdn2002 | Cezar (COCI16_cezar) | C++14 | 3 ms | 376 KB |
#include<bits/stdc++.h> using namespace std; const long long mod=998244353; int n,vis[39]; vector<int>gr[40]; vector<string>v,a; string s; void ckl(int x) { vis[x]=1; for(int i=0;i<gr[x].size();i++) { int u=gr[x][i]; if(vis[u]==1) { cout<<"NE"; exit(0); } else if(vis[u]==0)ckl(u); } vis[x]=2; } void dfs(int x) { vis[x-1]=1; s.push_back((x+'a')-1); for(int i=0;i<gr[x].size();i++) { int u=gr[x][i]; if(vis[u-1])continue; dfs(u); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen("lemonade.in","r",stdin); //freopen("lemonade.out","w",stdout); cin>>n; for(int i=0;i<n;i++) { string s; cin>>s; v.push_back(s); } for(int i=0;i<n;i++) { int x; cin>>x; a.push_back(v[x-1]); } for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { for(int z=0;z<min(a[i].size(),a[j].size());z++) { if(a[i][z]!=a[j][z]) { gr[(a[i][z]-'a')+1].push_back((a[j][z]-'a')+1); break; } if(a[i].size()>=a[j].size()&&z==a[j].size()-1) { cout<<"NE"; return 0; } } } } for(int i=1;i<=30;i++) { if(vis[i]==0)ckl(i); } memset(vis,0,sizeof vis); for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { for(int z=0;z<min(a[i].size(),a[j].size());z++) { if(a[i][z]!=a[j][z]) { if(vis[a[i][z]-'a']==0)dfs((a[i][z]-'a')+1); break; } } } } for(int i=0;i<='z'-'a';i++) { if(vis[i]==0)s.push_back(i+'a'); } cout<<"DA"<<endl<<s<<endl; } /* 5 aaaaaaaaaaa aaaaaaaaaab aaaaaaaaaac aaaaaaaaaad aaaaaaaaaae 5 4 3 2 1 */
Compilation message
# | 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 | 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 | 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 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
# | 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 | 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 | - |