Submission #133370

# Submission time Handle Problem Language Result Execution time Memory
133370 2019-07-20T12:49:31 Z forelax Cezar (COCI16_cezar) C++14
10 / 100
3 ms 504 KB
#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > dir(26,vector<int> (26));
vector<int> visiting(26);
vector<int> visited(26);
vector<int> ord;
bool good=true;
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])continue;
        dfs(i);
        if(!good)return;
    }
    ord.push_back(ind);
    visited[ind]=true;
}
int main(){
    int n;
    cin>>n;
    vector<string> a(n),b(n);
    for(int i = 0 ; i < n ; i ++)cin>>a[i];
    for(int j = 0 , x ; j < n ; j ++){
        cin>>x;x--;
        b[j]=a[x];
    }
    for(int i = 0 ; i < n ; i ++){
        for(int j = i+1 ; j < n ; j ++){
            int ns=min(b[i].size(),b[j].size());
            if(b[i].substr(0,ns)==b[j].substr(0,ns)){
                if(b[i].size()<b[j].size())
                    continue;
                else{
                    cout<<"NE";
                    return 0;
                }
            }
            if(j!=i+1)continue;
            for(int k = 0 ; k < ns ; k ++){
                if(b[i][k]==b[j][k])continue;
                dir[b[i][k]-'a'][b[j][k]-'a']=true;
                break;
            }
        }
    }
    for(int i = 0 ; i < 26 ; i ++){
        if(visited[i])continue;
        dfs(i);
        if(!good){
            cout<<"NE";
            return 0;
        }
    }
    vector<char> rez(26);
    for(int i = 25 ; i >= 0 ; i --){
        rez[ord[i]]=char('a'+25-i);
    }
    cout<<"DA"<<endl;
    for(int i = 0 ; i < 26 ; i ++)
        cout<<rez[i];
}
# 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 3 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 -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 424 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 3 ms 348 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 256 KB Output isn't correct
2 Halted 0 ms 0 KB -