Submission #1023884

# Submission time Handle Problem Language Result Execution time Memory
1023884 2024-07-15T08:36:22 Z Double_Slash Cezar (COCI16_cezar) C++17
20 / 100
1 ms 604 KB
#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[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']++;
                break;
            }
        }
    }
    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

cezar.cpp: In function 'bool solve()':
cezar.cpp:12:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |         for (int j = 0; j < words[i].size(); ++j) {
      |                         ~~^~~~~~~~~~~~~~~~~
cezar.cpp:13:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |             if (j == words[i + 1].size()) return false;
      |                 ~~^~~~~~~~~~~~~~~~~~~~~~
# 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 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
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 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 -