Submission #88125

# Submission time Handle Problem Language Result Execution time Memory
88125 2018-12-03T21:40:25 Z jasony123123 Cezar (COCI16_cezar) C++11
70 / 100
3 ms 964 KB
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

char ans[100];
int n;
string s[120];
vector<int> eds[100];
int p[120];
int was[120];
vector<int> vv;

void dfs1(int v) {
	was[v] = 1;
	for (int u: eds[v]) {
		if (!was[u])
			dfs1(u);
		else if (was[u] == 1) {
			cout << "NE\n";
			exit(0);
		}
	}
	vv.push_back(v);
	was[v] = 2;
}



int main() {
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> s[i];
	for (int i = 0; i < n; ++i)
		cin >> p[i], --p[i];
	for (int i = 0; i < n - 1; ++i) {
		int kk = min(s[p[i]].size(), s[p[i + 1]].size());
		for (int j = 0; j < kk; ++j) {
			if (s[p[i]][j] != s[p[i + 1]][j]) {
				kk = j;
				break;
			}
		}
		if (kk == (int)s[p[i + 1]].size()) {
			cout << "NE\n";
			return 0;
		}
		if (kk == (int)s[p[i]].size())
			continue;
		eds[s[p[i + 1]][kk] - 'a'].push_back(s[p[i]][kk] - 'a');
	}
	for (int i = 0; i < 26; ++i)
		if (!was[i])
			dfs1(i);
	for (int i = 0; i < (int)vv.size(); ++i) {
		ans[vv[i]] = 'a' + i;
	}
	printf("DA\n");
	printf("%s\n", ans);
	return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 612 KB Output is correct
2 Correct 3 ms 648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 676 KB Output is correct
2 Correct 3 ms 804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 812 KB Output is correct
2 Correct 2 ms 812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 964 KB Output is correct
2 Correct 3 ms 964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 964 KB Output isn't correct
2 Halted 0 ms 0 KB -