Submission #159686

# Submission time Handle Problem Language Result Execution time Memory
159686 2019-10-24T00:50:43 Z socho Zamjena (COCI18_zamjena) C++14
28 / 70
21 ms 2568 KB
#include "bits/stdc++.h"
using namespace std;
 
bool isn(string s) {
	char x = s[0];
	if (x >= '0' && x <= '9') return true;
	return false;
}
 
 
int main(){
	
	int n;
	cin >> n;
	string a1[n], a2[n];
	for (int i=0; i<n; i++) cin >> a1[i];
	for (int i=0; i<n; i++) cin >> a2[i];
	
	map<string, bool> locked;
	map<string, string> lockto;
	
	vector<pair<string, string> > eq;
	
	for (int i=0; i<n; i++) {
		string a=a1[i], b=a2[i];
		if (a == b) continue;
		if (isn(a) && isn(b)) {
			if (a == b) continue;
			cout << "NE" << endl;
			exit(0);
		}
		else if (isn(a)) {
			if (locked[b]) {
				if (lockto[b] != a) {
					cout << "NE" << endl;
					exit(0);
				}
			}
			else {
				locked[b] = true;
				lockto[b] = a;
			}
		}
		else if (isn(b)) {
			if (locked[a]) {
				if (lockto[a] != b) {
					cout << "NE" << endl;
					exit(0);
				}
			}
			else {
				locked[a] = true;
				lockto[a] = b;
			}
		}
		else {
			if (locked[a]) {
				locked[b] = true;
				lockto[b] = lockto[a];
			}
			else if (locked[b]) {
				locked[a] = true;
				lockto[a] = lockto[b];
			}
			else {
				eq.push_back(make_pair(a, b));
			}
		}
	} 
	
	for (int i=0; i<eq.size(); i++) {
		string a = eq[i].first, b = eq[i].second;
		if (locked[a] && locked[b]) {
			if (lockto[a] != lockto[b]) {
				cout << "NE" << endl;
				exit(0);
			}
		}
	}
	
	cout << "DA" << endl;
	
}

Compilation message

zamjena.cpp: In function 'int main()':
zamjena.cpp:71:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0; i<eq.size(); i++) {
                ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Incorrect 2 ms 256 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 492 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Incorrect 8 ms 1016 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 2568 KB Output isn't correct
2 Halted 0 ms 0 KB -