Submission #88127

# Submission time Handle Problem Language Result Execution time Memory
88127 2018-12-03T21:42:20 Z jasony123123 Cezar (COCI16_cezar) C++11
30 / 100
3 ms 568 KB
#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 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 380 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 424 KB Output is correct
# 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 Incorrect 3 ms 568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 568 KB Output is correct
2 Correct 2 ms 568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 568 KB Output is correct
2 Correct 2 ms 568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 568 KB Output isn't correct
2 Halted 0 ms 0 KB -