Submission #201114

# Submission time Handle Problem Language Result Execution time Memory
201114 2020-02-09T11:13:53 Z SamAnd Cezar (COCI16_cezar) C++17
70 / 100
6 ms 376 KB
#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];

bool solv(int l, int r, int j)
{
    while (l <= r && a[l].size() <= j)
        ++l;
    if (l > r)
        return true;
    for (int i = l; i <= r; ++i)
    {
        if (a[i].size() <= j)
            return false;
    }
    int ll = l;
    for (int i = l + 1; i <= r; ++i)
    {
        if (a[i][j] != a[i - 1][j])
        {
            g[a[i][j] - 'a'].push_back(a[i - 1][j] - 'a');
            if (!solv(ll, i - 1, j + 1))
                return false;
            ll = i;
        }
    }
    if (!solv(ll, r, j + 1))
        return false;
    return true;
}

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]];
    }
    if (!solv(1, n, 0))
    {
        cout << "NE" << endl;
        return 0;
    }
    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;
    for (int i = 0; i < 26; ++i)
        cout << ans[i];
    cout << endl;
    return 0;
}

Compilation message

cezar.cpp: In function 'bool solv(int, int, int)':
cezar.cpp:14:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (l <= r && a[l].size() <= j)
                      ~~~~~~~~~~~~^~~~
cezar.cpp:20:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (a[i].size() <= j)
             ~~~~~~~~~~~~^~~~
cezar.cpp: In function 'bool dfs(int)':
cezar.cpp:44: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:63: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:111:17: warning: array subscript has type 'char' [-Wchar-subscripts]
         ans[v[i]] = i + 'a';
                 ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 128 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -