# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
171680 |
2019-12-29T23:02:56 Z |
Tuk1352 |
Cezar (COCI16_cezar) |
C++11 |
|
2 ms |
376 KB |
#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[26];
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)
{
t++;
c1 = 'a'+t-1;
c[i] = c1;
T.push_back(i);
}
}
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)
{
t++;
c1 = 'a'+t-1;
c[b] = c1;
T.push_back(b);
}
}
}
for (int i = 0; i < 26; i++)
{
if (P[i] == 0)
{
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
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:66:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < T.size(); i++)
~~^~~~~~~~~~
cezar.cpp:69:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int y = 0; y < D[a].size(); y++)
~~^~~~~~~~~~~~~
cezar.cpp:16:14: warning: iteration 26 invokes undefined behavior [-Waggressive-loop-optimizations]
P[i] = 0;
~~~~~^~~
cezar.cpp:13:23: note: within this loop
for (int i = 0; i < 27; i++)
~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 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 |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 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 |
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 |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |