Submission #83381

# Submission time Handle Problem Language Result Execution time Memory
83381 2018-11-07T13:13:23 Z luciocf Cezar (COCI16_cezar) C++14
30 / 100
4 ms 680 KB
#include <bits/stdc++.h>

using namespace std;

const int maxs = 30;

const int maxn = 110;

typedef pair<int, string> pii;

int grau[maxs], ans[maxs];

pii num[maxn];

vector<int> grafo[maxs];

string s[maxn];

int main(void)
{
	int n;
	cin >> n;

	for (int i = 1; i <= n; i++)
		cin >> num[i].second;

	for (int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;

		num[x].first = i;
	}

	sort(num+1, num+n+1);

	bool ok = 1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = i+1; j <= n; j++)
		{
			string s1 = num[i].second, s2 = num[j].second;
			bool prefixo = 1;

			for (int k = 0; k < min(s1.size(), s2.size()); k++)
			{
				if (s1[k] == s2[k]) continue;

				grafo[s1[k]-'a'].push_back(s2[k]-'a');
				grau[s2[k]-'a']++, prefixo = 0;

				break;
			}

			if (prefixo && s1.size() > s2.size()) ok = 0;
		}
	}

	if (!ok)
	{
		cout << "NE\n";
		return 0;
	}

	queue<int> fila;
	for (int i = 0; i < 26; i++)
		if (!grau[i])
			fila.push(i);

	int atual = 0;
	while (!fila.empty())
	{
		int x = fila.front();
		fila.pop();

		ans[x] = atual++;

		for (auto v: grafo[x])
		{
			grau[v]--;
			if (!grau[v]) fila.push(v);
		}
	}

	for (int i = 0; i < 26; i++)
	{
		if (grau[i])
		{
			cout << "NE\n";
			return 0;
		}
	}
	
	cout << "DA\n";
	for (int i = 0; i < 26; i++)
		cout << (char) (ans[i]+'a');
	cout << "\n";
}

Compilation message

cezar.cpp: In function 'int main()':
cezar.cpp:45:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int k = 0; k < min(s1.size(), s2.size()); k++)
                    ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 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 508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 556 KB Output is correct
2 Correct 2 ms 556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 636 KB Output is correct
2 Correct 3 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 680 KB Output is correct
2 Correct 3 ms 680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 680 KB Output isn't correct
2 Halted 0 ms 0 KB -