Submission #91146

#TimeUsernameProblemLanguageResultExecution timeMemory
91146nikolapesic2802Cezar (COCI16_cezar)C++14
70 / 100
2 ms1012 KiB
#include <iostream> #include <fstream> #include <set> #include <map> #include <string> #include <vector> #include <bitset> #include <algorithm> #include <cstring> #include <cstdlib> #include <cmath> #include <cassert> #include <queue> #define mp make_pair #define pb push_back typedef long long ll; typedef long double ld; using namespace std; char ans[100]; int n; string s[120]; vector<int> eds[100]; int p[120]; int was[120]; vector<int> vv; void dfs1(int v) { was[v] = 1; for (int u: eds[v]) { if (!was[u]) dfs1(u); else if (was[u] == 1) { cout << "NE\n"; exit(0); } } vv.push_back(v); was[v] = 2; } int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> s[i]; for (int i = 0; i < n; ++i) cin >> p[i], --p[i]; for (int i = 0; i < n - 1; ++i) { int kk = min(s[p[i]].size(), s[p[i + 1]].size()); for (int j = 0; j < kk; ++j) { if (s[p[i]][j] != s[p[i + 1]][j]) { kk = j; break; } } if (kk == (int)s[p[i + 1]].size()) { cout << "NE\n"; return 0; } if (kk == (int)s[p[i]].size()) continue; eds[s[p[i + 1]][kk] - 'a'].push_back(s[p[i]][kk] - 'a'); } for (int i = 0; i < 26; ++i) if (!was[i]) dfs1(i); for (int i = 0; i < (int)vv.size(); ++i) { ans[vv[i]] = 'a' + i; } printf("DA\n"); printf("%s\n", ans); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...