# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
133399 | tdwn | Cezar (COCI16_cezar) | C++17 | 3 ms | 376 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>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 110;
string tempstr[maxn];
string str[maxn];
int perm[maxn], n;
vector<int>g[30], rg[30];
int visited[maxn];
vector<int>order;
bool cycle;
bool edge[maxn][maxn];
void dfs(int node) {
if(visited[node] == 2) return;
if(visited[node] == 1) {
cycle = true;
return;
}
visited[node] = 1;
for(int i:g[node]) {
if(visited[i] == 0) {
dfs(i);
}
else if(visited[i] == 1) {
cycle = true;
}
}
visited[node] = 2;
order.pb(node);
}
int main() {
cin>>n;
for(int i=1;i<=n;i++) {
cin>>tempstr[i];
}
for(int i=1;i<=n;i++) {
cin>>perm[i];
}
for(int i=1;i<=n;i++) {
str[i] = tempstr[perm[i]];
}
for(int i=1;i<=n;i++) {
for(int j=i+1;j<=n;j++) {
if(str[j].length() < str[i].length()) {
if(str[i].substr(0, str[j].length()) == str[j]) {
cout<<"NE\n";
return 0;
}
}
}
}
for(int i=1;i<=n;i++) {
for(int j=i+1;j<=n;j++) {
for(int k=0;k<min(int(str[i].length()), int(str[j].length()));k++) {
if(str[i][k] != str[j][k]) {
edge[int(str[i][k]-'a')][int(str[j][k]-'a')] = true;
break;
}
}
}
}
for(int i=0;i<26;i++) {
for(int j=0;j<26;j++) {
if(edge[i][j]) g[i].pb(j);
}
}
for(int i=25;i>=0;i--) {
if(visited[i] == 0) dfs(i);
}
if(cycle) {
cout<<"NE\n";
return 0;
}
cout<<"DA\n";
reverse(order.begin(), order.end());
for(int i=0;i<order.size();i++) {
cout<<char(order[i]+'a');
}
}
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... |