Submission #133281

# Submission time Handle Problem Language Result Execution time Memory
133281 2019-07-20T10:52:58 Z forelax Cezar (COCI16_cezar) C++14
20 / 100
3 ms 524 KB
#include<bits/stdc++.h>
using namespace std;
int n;
vector<pair<int,string> > v;
vector<vector<int> > dir(26,vector<int> (26));
bool good=true;
void attack(int b,int e,int c){
    int l=e-b;
    if(l<2)return;
    vector<char> tht(l);
    vector<bool> seen(26);
    for(int i = b ; i < e ; i ++)
        tht[i-b]=c<v[i].second.length()?v[i].second[c]:' ';
    bool f=false;
    for(int i = 0 ; i < l ; i ++){
        if(tht[i]!=' ')f=true;
        else{
            if(f){
                good=false;
                return;
            }
        }
    }
    for(int i = l-1,j ; i >= 0 ; ){
        j=i;
        while(j>=0&&tht[j]==tht[i])
            j--;
        if(tht[i]!=' '){
            int ch=tht[i]-'a';
            if(seen[ch]){
                good=false;
                return;
            }
            for(int k = 0 ; k < 26 ; k ++){
                if(seen[k]){
                    if(dir[k][ch]){
                        good=false;
                        return;
                    }
                    dir[ch][k]=true;
                }
            }
            attack(b+j+1,b+i+1,c+1);
            seen[tht[i]-'a']=true;
        }
        i=j;
    }
}
vector<int> visited(26);
vector<int> visiting(26);
vector<int> rez;
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);
        }
    }
    rez.push_back(ind);
    visited[ind]=true;
}
int main(){
    cin>>n;
    v.resize(n);
    for(int i = 0 ; i < n ; i ++){
        cin>>v[i].second;
    }
    for(int j = 0 ; j < n ; j ++){
        cin>>v[j].first;
    }
    sort(v.begin(),v.end());
    attack(0,n,0);
    if(!good){
        cout<<"NE";
        return 0;
    }
    for(int i = 26 ; i >= 0 ; i --){
        if(!visited[i]){
            dfs(i);
        }
    }
    if(!good){
        cout<<"NE";
        return 0;
    }
    cout<<"DA"<<endl;
    vector<char> ord(26);
    for(int i = 0 ; i < rez.size() ; i ++){
        ord[rez[i]]=char('a'+25-i);
    }
    for(int i = 0 ; i < 26 ; i ++)cout<<ord[i];
}

Compilation message

cezar.cpp: In function 'void attack(int, int, int)':
cezar.cpp:13:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         tht[i-b]=c<v[i].second.length()?v[i].second[c]:' ';
                  ~^~~~~~~~~~~~~~~~~~~~~
cezar.cpp: In function 'int main()':
cezar.cpp:92:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0 ; i < rez.size() ; i ++){
                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 524 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 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 504 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 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 348 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 -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -