Submission #81593

# Submission time Handle Problem Language Result Execution time Memory
81593 2018-10-25T13:36:50 Z pzdba Cezar (COCI16_cezar) C++14
0 / 100
3 ms 784 KB
#include <bits/stdc++.h>
using namespace std;
string s[105];
bool adj[26][26], adj2[26][26];
int deg[26];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> s[i];
	}
	vector<int> order;
	for(int i=1;i<=n;i++){
		int x;
		cin >> x;
		order.emplace_back(x);
	}
	int pv = 0;
	for(int i=0;i<order.size();i++){
		int idx = order[i];
		if(i != 0){
			int mn = min(s[idx].length(), s[pv].length());
			for(int j=0;j<mn;j++){
				if(s[idx][j] == s[pv][j]) continue;
				int c1 = s[pv][j]-'a';
				int c2 = s[idx][j]-'a';
				adj[c1][c2] = 1;
				adj2[c1][c2] = 1;
				break;
			}
		}
		pv = idx;
	}

	for(int k=0;k<26;k++){
		for(int i=0;i<26;i++){
			for(int j=0;j<26;j++){
				adj[i][j] = adj[i][j] | (adj[i][k] & adj[k][j]);
			}
		}
	}
	for(int i=0;i<26;i++){
		for(int j=0;j<26;j++){
			if(adj[i][j] && adj[j][i]) return !printf("NE\n");
			if(adj2[i][j]) deg[j]++;
		}
	}
	queue<int> q;
	for(int i=0;i<26;i++){
		if(deg[i] == 0) q.push(i);
	}
	printf("DA\n");
	while(!q.empty()){
		int u = q.front();
		q.pop();
		printf("%c", u+'a');
		for(int v=0;v<26;v++){
			if(!adj2[u][v]) continue;
			deg[v]--;
			if(deg[v] == 0) q.push(v);
		}
	}
}

Compilation message

cezar.cpp: In function 'int main()':
cezar.cpp:21:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<order.size();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 2 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Incorrect 2 ms 608 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 608 KB Output is correct
2 Incorrect 3 ms 608 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 608 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 784 KB Output isn't correct
2 Halted 0 ms 0 KB -