Submission #133398

# Submission time Handle Problem Language Result Execution time Memory
133398 2019-07-20T14:03:59 Z tdwn Cezar (COCI16_cezar) C++17
20 / 100
3 ms 376 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;

void dfs(int node) {
	if(visited[node] == 2) return;
	if(visited[node] == 1) {
		visited[node] = 2;
		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[perm[i]] = tempstr[i];
	}

	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 j=i+1;j<=n;j++) {
			for(int k=0;k<min(int(str[i].length()), int(str[j].length()));k++) {
				if(str[i][k] != str[j][k]) {
					g[int(str[i][k]-'a')].pb(int(str[j][k]-'a'));
					break;
				}
			}
		}
	}

	for(int i=25;i>=0;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:83: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 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 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 Correct 2 ms 348 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 3 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 256 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 372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 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 -