Submission #201117

#TimeUsernameProblemLanguageResultExecution timeMemory
201117SamAndCezar (COCI16_cezar)C++17
70 / 100
6 ms376 KiB
#include <bits/stdc++.h> using namespace std; const int N = 102; int n; string a[N]; string b[N]; int u[N]; vector<int> g[26]; int c[26]; bool dfs(int x) { c[x] = 1; for (int i = 0; i < g[x].size(); ++i) { int h = g[x][i]; if (c[h] == 1) return false; if (!c[h]) { if (!dfs(h)) return false; } } c[x] = 2; return true; } vector<char> v; void dfs1(int x) { c[x] = 1; for (int i = 0; i < g[x].size(); ++i) { int h = g[x][i]; if (!c[h]) dfs1(h); } v.push_back(x); } char ans[33]; int main() { //freopen("input.txt", "r", stdin); cin >> n; for (int i = 1; i <= n; ++i) cin >> b[i]; for (int i = 1; i <= n; ++i) cin >> u[i]; for (int i = 1; i <= n; ++i) { a[i] = b[u[i]]; } for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { bool z = true; if (a[i].size() <= a[j].size()) continue; for (int k = 0; k < a[j].size(); ++k) { if (a[j][k] != a[i][k]) { z = false; break; } } if (z) { cout << "NE" << endl; return 0; } } } for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { for (int k = 0; ; ++k) { if (k == a[i].size() || k == a[j].size()) break; if (a[i][k] != a[j][k]) { g[a[j][k] - 'a'].push_back(a[i][k] - 'a'); break; } } } } for (int i = 0; i < 26; ++i) { if (!c[i]) { if (!dfs(i)) { cout << "NE" << endl; return 0; } } } memset(c, 0, sizeof c); for (int i = 0; i < 26; ++i) { if (!c[i]) { dfs1(i); } } for (int i = 0; i < 26; ++i) ans[v[i]] = i + 'a'; cout << "DA" << endl; cout << ans << endl; return 0; }

Compilation message (stderr)

cezar.cpp: In function 'bool dfs(int)':
cezar.cpp:17:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < g[x].size(); ++i)
                     ~~^~~~~~~~~~~~~
cezar.cpp: In function 'void dfs1(int)':
cezar.cpp:36:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < g[x].size(); ++i)
                     ~~^~~~~~~~~~~~~
cezar.cpp: In function 'int main()':
cezar.cpp:66:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int k = 0; k < a[j].size(); ++k)
                             ~~^~~~~~~~~~~~~
cezar.cpp:87:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if (k == a[i].size() || k == a[j].size())
                     ~~^~~~~~~~~~~~~~
cezar.cpp:87:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if (k == a[i].size() || k == a[j].size())
                                         ~~^~~~~~~~~~~~~~
cezar.cpp:117:17: warning: array subscript has type 'char' [-Wchar-subscripts]
         ans[v[i]] = i + 'a';
                 ^
#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...