# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
83433 | Leonardo_Paes | Cezar (COCI16_cezar) | C++11 | 4 ms | 672 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;
typedef pair<int,string> pis;
#define MAXN 110
pis vet[MAXN];
int mat[26][26], mark[26];
stack<int> pilha;
void dfs(int u){
mark[u]=1;
for(int i=0; i<=25; i++){
if(mat[u][i]==1 and mark[i]==0){
dfs(i);
}
}
pilha.push(u);
}
int main(){
int n;
cin >> n;
for(int i=1; i<=n; i++){
cin >> vet[i].second;
}
for(int i=1; i<=n; i++){
cin >> vet[i].first;
}
sort(vet+1, vet+n+1);
for(int i=1; i<n; i++){
for(int j=i+1; j<=n; j++){
string a = vet[i].second;
string b = vet[j].second;
int siz = max(a.size(), b.size());
for(int k=0; k<siz; k++){
if(k+1==a.size() or k+1==b.size()){
break;
}
if(a[k] != b[k]){
mat[b[k]-'a'][a[k]-'a'] = 1;
break;
}
}
}
}
for(int i=0; i<=25; i++){
for(int j=0; j<=25; j++){
if(mat[i][j]==1 and mat[j][i]==1){
cout << "NE" << endl;
return 0;
}
}
}
cout << "DA" << endl;
for(int i=0; i<=25; i++){
if(mark[i]==0){
dfs(i);
stack<int> pilha2;
while(!pilha.empty()){
pilha2.push(pilha.top());
pilha.pop();
}
while(!pilha2.empty()){
cout << char(pilha2.top() + (int)'a');
pilha2.pop();
}
}
}
return 0;
}
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... |