답안 #171681

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
171681 2019-12-29T23:09:43 Z Tuk1352 Cezar (COCI16_cezar) C++11
60 / 100
3 ms 504 KB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, la, lb, t=0, a, b;
    cin >> n;
    string S[n], s[n];
    int A[n], K[27], P[27];
    vector <int> D[27], T;
    char c1, c2, c[26];
    for (int i = 0; i < 27; i++)
    {
        K[i] = 0;
        P[i] = 0;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> S[i];
        for (int y = 0; y < S[i].length(); y++)
        {
            P[S[i][y]-'a'] = 1;
        }
    }
    for (int i = 0; i < n; i++)
    {
        cin >> A[i];
        s[i] = S[A[i]-1];
    }
    for (int i = 1; i < n; i++)
    {
        la = s[i-1].length();
        lb = s[i].length();
        int g = 1;
        for (int y = 0; y < min(la,lb); y++)
        {
            if (s[i-1][y] != s[i][y])
            {
                g = 0;
                c1 = s[i-1][y];
                c2 = s[i][y];
                a = c1 - 'a';
                b = c2 - 'a';
                D[a].push_back(b);
                K[b]++;
                break;
            }
        }
        if (g == 1 && la > lb)
        {
            cout << "NE";
            return 0;
        }
    }
    for (int i = 0; i < 26; i++)
    {
        if (K[i] == 0 && P[i] == 1 && D[i].size() != 0)
        {
            t++;
            c1 = 'a'+t-1;
            c[i] = c1;
            T.push_back(i);
            K[i] = -1;
        }
    }
    for (int i = 0; i < T.size(); i++)
    {
        a = T[i];
        for (int y = 0; y < D[a].size(); y++)
        {
            b = D[a][y];
            K[b]--;
            if (K[b] == 0)
            {
                K[b] = -1;
                t++;
                c1 = 'a'+t-1;
                c[b] = c1;
                T.push_back(b);
            }
        }
    }
    for (int i = 0; i < 26; i++)
    {
        if (P[i] == 0 || (P[i] == 1 && D[i].size() == 0 && K[i] != -1))
        {
            t++;
            c1 = 'a'+t-1;
            c[i] = c1;
        }
    }
    if (t != 26)
    {
        cout << "NE";
        return 0;
    }
    cout << "DA" << "\n";
    for (int i = 0; i < 26; i++)
    {
        cout << c[i];
    }
    return 0;
}

Compilation message

cezar.cpp: In function 'int main()':
cezar.cpp:21:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int y = 0; y < S[i].length(); y++)
                         ~~^~~~~~~~~~~~~~~
cezar.cpp:67:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < T.size(); i++)
                     ~~^~~~~~~~~~
cezar.cpp:70:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int y = 0; y < D[a].size(); y++)
                         ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -