답안 #98266

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
98266 2019-02-21T18:07:48 Z dalgerok Cezar (COCI16_cezar) C++17
80 / 100
15 ms 512 KB
#include<bits/stdc++.h>
using namespace std;


const int N = 1050, M = 26;




int n, cl[N];
int a[M][M], in[M];
string s[N], t[N];
vector < int > order;
char ans[M];


void dfs1(int v){
    if(cl[v] == 1){
        cout << "NE";
        exit(0);
    }
    cl[v] = 1;
    for(int to = 0; to < M; to++){
        if(a[v][to]){
            dfs1(to);
        }
    }
    cl[v] = 0;
}

void dfs2(int v){
    if(cl[v]){
        return;
    }
    cl[v] = 1;
    for(int to = 0; to < M; to++){
        if(a[v][to]){
            dfs2(to);
        }
    }
    order.push_back(v);
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> s[i];
        for(auto &it : s[i]){
            it -= 'a';
        }
    }
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        t[i] = s[x];
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j < i; j++){
            if((int)t[i].size() < (int)t[j].size() && t[j].substr(0, (int)t[i].size()) == t[i]){
                return cout << "NE", 0;
            }
        }
    }
    for(int i = 2; i <= n; i++){
        for(int j = 0; j < min((int)t[i - 1].size(), (int)t[i].size()); j++){
            if(t[i - 1][j] != t[i][j]){
                if(a[t[i][j]][t[i - 1][j]] == 0){
                    a[t[i][j]][t[i - 1][j]] = 1;
                    in[t[i - 1][j]] += 1;
                }
                break;
            }
        }
    }
    for(int i = 0; i < M; i++){
        memset(cl, 0, sizeof(cl));
        dfs1(i);
    }
    memset(cl, 0, sizeof(cl));
    for(int i = 0; i < M; i++){
        if(in[i] == 0){
            dfs2(i);
        }
    }
    for(int i = 0; i < M; i++){
        ans[order[i]] = i;
    }
    cout << "DA\n";
    for(int i = 0; i < M; i++){
        cout << char(ans[i] + 'a');
    }
}

Compilation message

cezar.cpp: In function 'int main()':
cezar.cpp:68:29: warning: array subscript has type 'char' [-Wchar-subscripts]
                 if(a[t[i][j]][t[i - 1][j]] == 0){
                             ^
cezar.cpp:68:42: warning: array subscript has type 'char' [-Wchar-subscripts]
                 if(a[t[i][j]][t[i - 1][j]] == 0){
                                          ^
cezar.cpp:69:30: warning: array subscript has type 'char' [-Wchar-subscripts]
                     a[t[i][j]][t[i - 1][j]] = 1;
                              ^
cezar.cpp:69:43: warning: array subscript has type 'char' [-Wchar-subscripts]
                     a[t[i][j]][t[i - 1][j]] = 1;
                                           ^
cezar.cpp:70:35: warning: array subscript has type 'char' [-Wchar-subscripts]
                     in[t[i - 1][j]] += 1;
                                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 488 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -