Submission #88127

#TimeUsernameProblemLanguageResultExecution timeMemory
88127jasony123123Cezar (COCI16_cezar)C++11
30 / 100
3 ms568 KiB
#include <bits/stdc++.h> using namespace std; typedef long long lint; typedef pair<int, int> pi; int n, a[105]; char str[105][105]; int adj[26][26], deg[26], topo[26]; int main(){ cin >> n; for(int i=0; i<n; i++) cin >> str[i]; for(int i=0; i<n; i++){ cin >> a[i]; a[i]--; } for(int i=0; i+1<n; i++){ int j = 0; while(1){ if(str[a[i]][j] != str[a[i+1]][j]){ break; } j++; } if(str[a[i]][j] == 0){ continue; } else if(str[a[i+1]][j] == 0){ puts("NE"); return 0; } else{ adj[str[a[i]][j] - 'a'][str[a[i+1]][j] - 'a'] = 1; } } for(int i=0; i<26; i++){ for(int j=0; j<26; j++){ if(adj[i][j]) deg[j]++; } } queue<int> que; for(int i=0; i<26; i++){ if(!deg[i]) que.push(i); } int piv = 0; while(!que.empty()){ int x = que.front(); que.pop(); topo[x] = piv++; for(int i=0; i<26; i++){ if(adj[x][i]){ deg[i]--; if(deg[i] == 0) que.push(i); } } } if(piv != 26){ puts("NE"); return 0; } puts("DA"); for(int i=0; i<26; i++) printf("%c", topo[i] + 'a'); }
#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...