Submission #1023892

#TimeUsernameProblemLanguageResultExecution timeMemory
1023892Double_SlashCezar (COCI16_cezar)C++17
30 / 100
1 ms496 KiB
#include <bits/stdc++.h> #define debug(x) [&] { auto _x = x; cerr << __LINE__ << ": " << #x << " = " << _x << endl; return _x; }() using namespace std; int n, deg[26], ans[26]; string raw[101], words[101]; vector<int> adj[26]; bool comp(int i, int j) { for (int k = 0; k < words[i].size(); ++k) { if (k == words[j].size()) return false; if (words[i][k] != words[j][k]) { adj[words[i][k] - 'a'].emplace_back(words[j][k] - 'a'); deg[words[j][k] - 'a']++; break; } } return true; } bool solve() { for (int i = 1; i < n; ++i) { for (int j = i + 1; j <= n; ++j) { if (not comp(i, j)) return false; } } queue<int> q; for (int i = 0; i < 26; ++i) { if (not deg[i]) q.emplace(i); } int idx = 0; while (not q.empty()) { int i = q.front(); q.pop(); ans[i] = idx++; for (int j: adj[i]) { if (not --deg[j]) q.emplace(j); } } if (idx < 26) return false; cout << "DA\n"; for (int i = 0; i < 26; ++i) cout << (char) ('a' + ans[i]); cout << endl; return true; } int main() { cin >> n; for (int i = 1; i <= n; ++i) cin >> raw[i]; for (int i = 1; i <= n; ++i) { int j; cin >> j; words[i] = raw[j]; } if (not solve()) cout << "NE\n"; else { for (int i = 1; i <= n; ++i) { for (char &c: words[i]) { c = ans[c - 'a'] + 'a'; } if (i > 1) assert(words[i] > words[i - 1]); } } }

Compilation message (stderr)

cezar.cpp: In function 'bool comp(int, int)':
cezar.cpp:11:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for (int k = 0; k < words[i].size(); ++k) {
      |                     ~~^~~~~~~~~~~~~~~~~
cezar.cpp:12:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |         if (k == words[j].size()) return false;
      |             ~~^~~~~~~~~~~~~~~~~~
#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...