Submission #1023845

#TimeUsernameProblemLanguageResultExecution timeMemory
1023845Double_SlashCezar (COCI16_cezar)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; int n, deg[26], ans[26]; string raw[100], words[101]; vector<int> adj[26]; bool solve() { for (int i = 1; i < n; ++i) { for (int j = 0; j < words[i].size(); ++j) { if (j == words[i + 1].size()) return false; if (words[i][j] != words[i + 1][j]) { adj[words[i][j] - 'a'].emplace_back(words[i + 1][j] - 'a'); deg[words[i + 1][j] - 'a']++; } } } 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; for (int i = 0; i < 26; ++i) cout << (char) ('a' + ans[i]); cout << endl; return true; } int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> raw[i]; for (int i = 0; i < n; ++i) { int j; cin >> j; words[j] = raw[i]; } if (not solve()) cout << "NE\n"; }

Compilation message (stderr)

cezar.cpp: In function 'bool solve()':
cezar.cpp:11:27: 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 j = 0; j < words[i].size(); ++j) {
      |                         ~~^~~~~~~~~~~~~~~~~
cezar.cpp:12:19: 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 (j == words[i + 1].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...