Submission #133292

# Submission time Handle Problem Language Result Execution time Memory
133292 2019-07-20T11:26:11 Z forelax Cezar (COCI16_cezar) C++14
40 / 100
3 ms 504 KB
#include<bits/stdc++.h>
using namespace std;
int n;
vector<string> s,v;
vector<vector<int> > dir(26,vector<int> (26));
bool good=true;
vector<int> visiting(26);
vector<int> visited(26);
vector<int> ord;
void dfs(int ind){
    if(visiting[ind]){
        good=false;
        return;
    }
    visiting[ind]=true;
    for(int i = 0 ; i < 26 ; i ++){
        if(dir[ind][i]&&!visited[i]){
            dfs(i);
            if(!good)return;
        }
    }
    ord.push_back(ind);
    visited[ind]=true;
}
int main(){
    cin>>n;
    v.resize(n);
    s.resize(n);
    for(int i = 0 ; i < n ; i ++)
        cin>>v[i];
    for(int i = 0,a ; i < n ; i ++){
        cin>>a;
        a--;
        s[i]=v[a];
    }
    for(int i = 0 ; i < n-1 ; i ++){
        int ml=min(s[i].length(),s[i+1].length());
        if(s[i].substr(0,ml)==s[i+1].substr(0,ml)){
            if(s[i+1].length()<s[i].length()){
                cout<<"NE";
                return 0;
            }else continue;
        }
        for(int j = 0 ; j < s[i].length() && j<s[i+1].length() ; j ++){
            if(s[i][j]==s[i+1][j])continue;
            else{
                dir[s[i][j]-'a'][s[i+1][j]-'a']=true;
                break;
            }
        }
    }
    for(int i = 25 ; i>=0 ; i -- ){
        if(!visited[i])
            dfs(i);
        if(!good){
            cout<<"NE";
            return 0;
        }
    }
    reverse(ord.begin(),ord.end());
    vector<char> rez(26);
    for(int i = 0 ; i < 26 ; i ++){
        rez[ord[i]]=char('a'+i);
    }
    cout<<"DA"<<endl;
    for(int i = 0 ; i < 26 ; i++){
        cout<<rez[i];
    }
}

Compilation message

cezar.cpp: In function 'int main()':
cezar.cpp:44:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0 ; j < s[i].length() && j<s[i+1].length() ; j ++){
                         ~~^~~~~~~~~~~~~~~
cezar.cpp:44:47: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0 ; j < s[i].length() && j<s[i+1].length() ; j ++){
                                              ~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -