Submission #100739

# Submission time Handle Problem Language Result Execution time Memory
100739 2019-03-13T20:13:35 Z Ort Zamjena (COCI18_zamjena) C++11
70 / 70
252 ms 16376 KB
#include<iostream>
#include<string>
#include<vector>
#include<cctype>
#include<map>
#include<set>
#define MAX 50005
 
using namespace std;

int n;

set<string> visited;
map<string, vector<string> > M;
string a[MAX];
string b[MAX];

void dfs(string s) {
	for(auto it:M[s]) {
		if(visited.find(it)!=visited.end()) continue;
		visited.insert(it);
		dfs(it);
	}
}

bool isnumber(string ss) {
	if(isdigit(ss[0])) return 1;
	return 0;
}

bool check() {
	int cnt = 0;
	for(auto it:visited) if(isnumber(it)) cnt++;
	if(cnt>1) return 0;
	return 1;
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=0;i<n;i++) cin >> b[i];
	for(int i=0;i<n;i++) {
		M[a[i]].push_back(b[i]);
		M[b[i]].push_back(a[i]);
	}
	set<string> v;
	for(int i=0;i<n;i++) {
		if(v.find(a[i])==v.end()) {
			dfs(a[i]);
			if(check()) {
				for(auto it:visited) v.insert(it);
				visited.clear();
			}
			else {
				cout << "NE";
				return 0;
			}
		}
	}
	cout << "DA";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3456 KB Output is correct
2 Correct 4 ms 3456 KB Output is correct
3 Correct 5 ms 3428 KB Output is correct
4 Correct 5 ms 3584 KB Output is correct
5 Correct 5 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3428 KB Output is correct
2 Correct 5 ms 3456 KB Output is correct
3 Correct 4 ms 3456 KB Output is correct
4 Correct 4 ms 3456 KB Output is correct
5 Correct 5 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3456 KB Output is correct
2 Correct 4 ms 3456 KB Output is correct
3 Correct 5 ms 3456 KB Output is correct
4 Correct 5 ms 3456 KB Output is correct
5 Correct 5 ms 3456 KB Output is correct
6 Correct 5 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 3712 KB Output is correct
2 Correct 6 ms 3712 KB Output is correct
3 Correct 8 ms 4052 KB Output is correct
4 Correct 10 ms 4224 KB Output is correct
5 Correct 11 ms 4224 KB Output is correct
6 Correct 10 ms 4096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 5724 KB Output is correct
2 Correct 61 ms 7976 KB Output is correct
3 Correct 65 ms 9212 KB Output is correct
4 Correct 89 ms 11128 KB Output is correct
5 Correct 252 ms 16376 KB Output is correct
6 Correct 142 ms 12280 KB Output is correct