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;
int main()
{
int n, la, lb, t=0, a, b;
cin >> n;
string S[n], s[n];
int A[n], K[27], P[27];
vector <int> D[27], T;
char c1, c2, c[26];
for (int i = 0; i < 27; i++)
{
K[i] = 0;
P[i] = 0;
}
for (int i = 0; i < n; i++)
{
cin >> S[i];
for (int y = 0; y < S[i].length(); y++)
{
P[S[i][y]-'a'] = 1;
}
}
for (int i = 0; i < n; i++)
{
cin >> A[i];
s[i] = S[A[i]-1];
}
for (int i = 1; i < n; i++)
{
la = s[i-1].length();
lb = s[i].length();
int g = 1;
for (int y = 0; y < min(la,lb); y++)
{
if (s[i-1][y] != s[i][y])
{
g = 0;
c1 = s[i-1][y];
c2 = s[i][y];
a = c1 - 'a';
b = c2 - 'a';
D[a].push_back(b);
K[b]++;
break;
}
}
if (g == 1 && la > lb)
{
cout << "NE";
return 0;
}
}
for (int i = 0; i < 26; i++)
{
if (K[i] == 0 && P[i] == 1 && D[i].size() != 0)
{
t++;
c1 = 'a'+t-1;
c[i] = c1;
T.push_back(i);
K[i] = -1;
}
}
for (int i = 0; i < T.size(); i++)
{
a = T[i];
for (int y = 0; y < D[a].size(); y++)
{
b = D[a][y];
K[b]--;
if (K[b] == 0)
{
K[b] = -1;
t++;
c1 = 'a'+t-1;
c[b] = c1;
T.push_back(b);
}
}
}
for (int i = 0; i < 26; i++)
{
if (P[i] == 0 || (P[i] == 1 && D[i].size() == 0 && K[i] != -1))
{
t++;
c1 = 'a'+t-1;
c[i] = c1;
}
}
if (t != 26)
{
cout << "NE";
return 0;
}
cout << "DA" << "\n";
for (int i = 0; i < 26; i++)
{
cout << c[i];
}
return 0;
}
Compilation message (stderr)
cezar.cpp: In function 'int main()':
cezar.cpp:21:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int y = 0; y < S[i].length(); y++)
~~^~~~~~~~~~~~~~~
cezar.cpp:67:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < T.size(); i++)
~~^~~~~~~~~~
cezar.cpp:70:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int y = 0; y < D[a].size(); y++)
~~^~~~~~~~~~~~~
# | 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... |