Submission #86832

# Submission time Handle Problem Language Result Execution time Memory
86832 2018-11-27T17:08:06 Z jovitre Zamjena (COCI18_zamjena) C++14
42 / 70
70 ms 6720 KB
#include <bits/stdc++.h>

using namespace std;

#define MAXN 50005
#define MAXSZ 2050
#define INF 999999999
#define pb push_back

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <ll> vi;

int arr1[MAXN], arr2[MAXN];
string sArr1[MAXN], sArr2[MAXN];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;

	map <string, int> mapa;
	string in;
	int aux;

	bool isNum;

	for(int i = 1; i <= n; i++){
		cin >> in;
		isNum = true;

		if(in.size() <= 4){
			for(auto c : in){
				aux = c - '0';
				if(aux < 0 or aux > 9){
					isNum = false;
					break;
				}
			}
		} else isNum = false;

		if(isNum){
			arr1[i] = stoi(in);
			sArr1[i] = "";
		} else {
			arr1[i] = -1;
			sArr1[i] = in;
		}
	}

	for(int i = 1; i <= n; i++){
		cin >> in;
		isNum = true;

		if(in.size() <= 4){
			for(auto c : in){
				aux = c - '0';
				if(aux < 0 or aux > 9){
					isNum = false;
					break;
				}
			}
		} else isNum = false;

		if(isNum){
			arr2[i] = stoi(in);
			sArr2[i] = "";
		} else {
			arr2[i] = -1;
			sArr2[i] = in;
		}
	}

	bool ok = true;

	for(int i = 1; i <= n && ok; i++){
		if(arr1[i] != -1){
			if(arr2[i] != -1 && arr2[i] != arr1[i]) ok = false;
			else if(arr2[i] == -1){
				if(!mapa[sArr2[i]]) mapa[sArr2[i]] = arr1[i];
				else if(mapa[sArr2[i]] != arr1[i]) ok = false;
			}
		} else {
			if(arr2[i] == -1){
				if(!mapa[sArr1[i]] && !mapa[sArr2[i]]) continue;

				if(mapa[sArr1[i]] && !mapa[sArr2[i]]) mapa[sArr2[i]] = mapa[sArr1[i]];
				else if(!mapa[sArr1[i]] && mapa[sArr2[i]]) mapa[sArr1[i]] = mapa[sArr2[i]];
				else if(mapa[sArr1[i]] != mapa[sArr2[i]]) ok = false;
			}
			else if(arr2[i] != -1){
				if(!mapa[sArr1[i]]) mapa[sArr1[i]] = arr2[i];
				else if(mapa[sArr1[i]] != arr2[i]) ok = false;
			}
		}
	}

	for(int i = 1; i <= n && ok; i++){
		if(arr1[i] != -1){
			if(arr2[i] != -1 && arr2[i] != arr1[i]) ok = false;
			else if(arr2[i] == -1){
				if(!mapa[sArr2[i]]) mapa[sArr2[i]] = arr1[i];
				else if(mapa[sArr2[i]] != arr1[i]) ok = false;
			}
		} else {
			if(arr2[i] == -1){
				if(!mapa[sArr1[i]] && !mapa[sArr2[i]]) continue;

				if(mapa[sArr1[i]] && !mapa[sArr2[i]]) mapa[sArr2[i]] = mapa[sArr1[i]];
				else if(!mapa[sArr1[i]] && mapa[sArr2[i]]) mapa[sArr1[i]] = mapa[sArr2[i]];
				else if(mapa[sArr1[i]] != mapa[sArr2[i]]) ok = false;
			}
			else if(arr2[i] != -1){
				if(!mapa[sArr1[i]]) mapa[sArr1[i]] = arr2[i];
				else if(mapa[sArr1[i]] != arr2[i]) ok = false;
			}
		}
	}

	cout << (ok ? "DA" : "NE") << endl;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3448 KB Output is correct
2 Correct 5 ms 3576 KB Output is correct
3 Correct 5 ms 3816 KB Output is correct
4 Correct 5 ms 3816 KB Output is correct
5 Correct 5 ms 3816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3816 KB Output is correct
2 Correct 5 ms 3816 KB Output is correct
3 Correct 5 ms 3816 KB Output is correct
4 Correct 5 ms 3816 KB Output is correct
5 Correct 5 ms 3888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3888 KB Output is correct
2 Correct 5 ms 3888 KB Output is correct
3 Correct 6 ms 4104 KB Output is correct
4 Correct 5 ms 4104 KB Output is correct
5 Correct 5 ms 4104 KB Output is correct
6 Incorrect 5 ms 4104 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4104 KB Output is correct
2 Correct 6 ms 4104 KB Output is correct
3 Correct 8 ms 4156 KB Output is correct
4 Correct 8 ms 4184 KB Output is correct
5 Correct 11 ms 4224 KB Output is correct
6 Correct 7 ms 4224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 4676 KB Output is correct
2 Correct 58 ms 5472 KB Output is correct
3 Incorrect 70 ms 6720 KB Output isn't correct
4 Halted 0 ms 0 KB -