답안 #31804

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
31804 2017-09-09T07:12:07 Z top34051 Cezar (COCI16_cezar) C++14
50 / 100
0 ms 2024 KB
#include<bits/stdc++.h>
using namespace std;
int n;
bool vis[30];
int ans[30];
string s[105], p[105];
vector<int> from[30], to[30];
vector<int> topo;
void dfs(int x) {
    int i;
    vis[x] = 1;
    for(i=0;i<from[x].size();i++) if(!vis[from[x][i]]) dfs(from[x][i]);
    topo.push_back(x);
}
void dfs2(int x) {
    int i;
    vis[x] = 1;
    for(i=0;i<to[x].size();i++) if(!vis[to[x][i]]) dfs2(to[x][i]);
}
main() {
    int i,j,x;
    scanf("%d",&n);
    for(i=1;i<=n;i++) cin >> s[i];
    for(i=1;i<=n;i++) scanf("%d",&x), p[i] = s[x];
//    for(x=1;x<=n;x++) cout << p[x] << endl;
    for(x=1;x<n;x++) {
        i = j = 0;
        while(i<p[x].size() && j<p[x+1].size()) {
            if(p[x][i]!=p[x+1][j]) {
                to[p[x][i]-'a'].push_back(p[x+1][j]-'a');
                from[p[x+1][j]-'a'].push_back(p[x][i]-'a');
//                printf("%c -> %c\n",p[x][i],p[x+1][j]);
                break;
            }
            i++; j++;
        }
        if((i==p[x].size() || j==p[x+1].size()) && p[x].size()>p[x+1].size()) {
            printf("%d",1/0);
            return 0;
        }
    }
    memset(vis,0,sizeof(vis));
    for(x=0;x<26;x++) if(!vis[x]) dfs(x);
    memset(vis,0,sizeof(vis));
    for(i=25;i>=0;i--) {
        x = topo[i];
        if(vis[x]) {
            printf("NE");
            return 0;
        }
        dfs2(x);
    }
    printf("DA\n");
    for(i=0;i<26;i++) ans[topo[i]] = i;
    for(i=0;i<26;i++) printf("%c",ans[i]+'a');
}

Compilation message

cezar.cpp: In function 'void dfs(int)':
cezar.cpp:12:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<from[x].size();i++) if(!vis[from[x][i]]) dfs(from[x][i]);
              ^
cezar.cpp: In function 'void dfs2(int)':
cezar.cpp:18:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<to[x].size();i++) if(!vis[to[x][i]]) dfs2(to[x][i]);
              ^
cezar.cpp: At global scope:
cezar.cpp:20:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
cezar.cpp: In function 'int main()':
cezar.cpp:28:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(i<p[x].size() && j<p[x+1].size()) {
                ^
cezar.cpp:28:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(i<p[x].size() && j<p[x+1].size()) {
                                 ^
cezar.cpp:37:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if((i==p[x].size() || j==p[x+1].size()) && p[x].size()>p[x+1].size()) {
              ^
cezar.cpp:37:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if((i==p[x].size() || j==p[x+1].size()) && p[x].size()>p[x+1].size()) {
                                ^
cezar.cpp:38:26: warning: division by zero [-Wdiv-by-zero]
             printf("%d",1/0);
                          ^
cezar.cpp:22:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
cezar.cpp:24:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1;i<=n;i++) scanf("%d",&x), p[i] = s[x];
                                                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2024 KB Output is correct
2 Correct 0 ms 2024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2024 KB Output is correct
2 Correct 0 ms 2024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2024 KB Output is correct
2 Runtime error 0 ms 2024 KB Execution killed with signal 8 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2024 KB Output is correct
2 Correct 0 ms 2024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2024 KB Output is correct
2 Correct 0 ms 2024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2024 KB Output is correct
2 Runtime error 0 ms 2024 KB Execution killed with signal 8 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2024 KB Output is correct
2 Correct 0 ms 2024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2024 KB Output isn't correct
2 Halted 0 ms 0 KB -