Submission #133380

#TimeUsernameProblemLanguageResultExecution timeMemory
133380forelaxCezar (COCI16_cezar)C++14
10 / 100
4 ms496 KiB
#include<bits/stdc++.h> using namespace std; bool pref(string a,string b){ int sm=min(a.length(),b.length()); string acut=a.substr(0,sm); string bcut=b.substr(0,sm); if(acut==bcut&&a.length()<b.length())return true; return false; } vector<vector<int> > ng(26); bool good=true; vector<int> visited(26); vector<int> visiting(26); vector<int> ord; void dfs(int a){ if(visiting[a]){ good=false; return; } visiting[a]=true; for(int i = 0 ; i < ng[a].size() ; i ++){ int b=ng[a][i]; if(visited[b])continue; dfs(b); if(!good)return; } ord.push_back(a); visited[a]=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 i = 0 , j; i < n ; i ++){ cin>>j;j--; b[i]=a[j]; } for(int i = 0 ; i < n ; i ++){ for(int j = 0 ; j < i ; j ++){ if(pref(b[i],b[j])){ cout<<"NE"; return 0; } } } for(int i = 0 ; i < n-1 ; i ++){ int j = i+1; if(pref(b[i],b[j]))continue; for(int k = 0 ; true ; k ++){ if(b[i][k]!=b[j][k]){ ng[b[i][k]-'a'].push_back(b[j][k]-'a'); 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 = 0 ; i <ord.size() ; i ++){ rez[ord[i]]=char('z'-i); } cout<<"DA"<<endl; for(int i = 0 ; i < 26 ; i ++)cout<<rez[i]; }

Compilation message (stderr)

cezar.cpp: In function 'void dfs(int)':
cezar.cpp:21:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0 ; i < ng[a].size() ; i ++){
                     ~~^~~~~~~~~~~~~~
cezar.cpp: In function 'int main()':
cezar.cpp:67:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0 ; i <ord.size() ; i ++){
                     ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...