Submission #133416

# Submission time Handle Problem Language Result Execution time Memory
133416 2019-07-20T14:53:21 Z tdwn Cezar (COCI16_cezar) C++17
20 / 100
3 ms 380 KB
#include <bits/stdc++.h>
#define ll long long 
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 110;
string tempstr[maxn];
string str[maxn];
int perm[maxn], n;

vector<int>g[30], rg[30];
int visited[maxn];
vector<int>order;

bool cycle;
bool edge[maxn][maxn];

void dfs(int node) {
	if(visited[node] == 2) return;
	if(visited[node] == 1) {
		cycle = true;
		return;
	}

	visited[node] = 1;
	for(int i:g[node]) {
		if(visited[i] == 0) {
			dfs(i);
		}
		else if(visited[i] == 1) {
			cycle = true;
		}
	}

	visited[node] = 2;
	order.pb(node);
}

int main() {
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>tempstr[i];
	}
	for(int i=1;i<=n;i++) {
		cin>>perm[i];
	}
	for(int i=1;i<=n;i++) {
		str[i] = tempstr[perm[i]];
	}

	/*for(int i=1;i<=n;i++) {
		for(int j=80;j<str[i].length();j++) {
			cout<<str[i][j];
		} cout<<"\n";
	}*/

	for(int i=1;i<=n;i++) {
		for(int j=i+1;j<=n;j++) {
			if(str[j].length() < str[i].length()) {
				if(str[i].substr(0, str[j].length()) == str[j]) {
					cout<<"NE\n";
					return 0;
				}
			}
		}
	}

	for(int i=1;i<n;i++) {
		for(int k=0;k<min(int(str[i].length()), int(str[i+1].length()));k++) {
			if(str[i][k] != str[i+1][k]) {
				edge[int(str[i][k]-'a')][int(str[i+1][k]-'a')] = true;
				break;
			}
		}
	}

	for(int i=0;i<26;i++) {
		for(int j=0;j<26;j++) {
			if(edge[i][j]) {
				//cout<<char(i+'a')<<", "<<char(j+'a')<<"\n";
				g[i].pb(j);
			}
		}
	}

	for(int i=0;i<26;i++) {
		if(visited[i] == 0) dfs(i);
	}

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

	cout<<"DA\n";
	//reverse(order.begin(), order.end());
	for(int i=0;i<order.size();i++) {
		cout<<char(order[i]+'a');
	}
}

Compilation message

cezar.cpp: In function 'int main()':
cezar.cpp:97: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 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 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 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 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 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -