# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
88126 | jasony123123 | Cezar (COCI16_cezar) | C++11 | 2 ms | 556 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 <stdio.h>
#include <queue>
using namespace std;
int N,P[111]; char S[111][111],ans[30];
bool f[26][26]; int d[26];
int main()
{
scanf ("%d",&N);
for (int i=1;i<=N;i++) scanf ("%s",S[i]);
for (int i=1;i<=N;i++) scanf ("%d",&P[i]);
bool good = 1;
for (int i=2;i<=N;i++){
for (int j=0;;j++){
if (S[P[i-1]][j] == 0) break;
if (S[P[i]][j] == 0) good = 0;
if (S[P[i-1]][j] != S[P[i]][j]){
f[S[P[i-1]][j]-'a'][S[P[i]][j]-'a'] = 1;
break;
}
}
}
for (int i=0;i<26;i++) for (int j=0;j<26;j++) if (f[i][j]) d[j]++;
queue<int> Q;
for (int i=0;i<26;i++) if (d[i] == 0) Q.push(i);
int c = 0;
while (!Q.empty()){
int x = Q.front(); Q.pop();
ans[x] = c + 'a'; c++;
for (int y=0;y<26;y++) if (f[x][y]){
if (--d[y] == 0) Q.push(y);
}
}
if (c < 26) good = 0;
if (good){
puts("DA");
puts(ans);
}
else{
puts("NE");
}
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... |