# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
991198 |
2024-06-01T14:38:16 Z |
LOLOLO |
Cezar (COCI16_cezar) |
C++17 |
|
1 ms |
348 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (ll)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 110;
string s[N];
string st[N];
int cc[N];
vector <int> ed[30];
vector <char> ans;
char pos[30];
bool visited[30];
void dfs(int v) {
visited[v] = true;
for (int u : ed[v]) {
if (!visited[u])
dfs(u);
}
ans.push_back(char(v + 'a'));
}
void topological_sort() {
ans.clear();
for (int i = 0; i < 26; ++i) {
if (!visited[i]) {
dfs(i);
}
}
reverse(ans.begin(), ans.end());
}
ll solve() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s[i];
}
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
st[i] = s[x];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
bool is = 0;
for (int k = 0; k < min(len(st[i]), len(st[j])); k++) {
if (st[i][k] != st[j][k]) {
is = 1;
ed[st[j][k] - 'a'].pb(st[i][k] - 'a');
break;
}
}
if (is == 0 && len(st[i]) < len(st[j])) {
cout << "NE\n";
return 0;
}
}
}
topological_sort();
for (int i = 0; i < 26; i++) {
pos[ans[i] - 'a'] = char(i + 'a');
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < len(st[i]); j++) {
st[i][j] = pos[st[i][j] - 'a'];
}
s[i] = st[i];
}
sort(s + 1, s + 1 + n);
for (int i = 1; i <= n; i++) {
if (s[i] != st[i]) {
cout << "NE\n";
return 0;
}
}
cout << "DA\n";
for (int i = 0; i < 26; i++)
cout << ans[i];
return 0;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |