답안 #95550

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
95550 2019-02-02T03:32:00 Z kimcoding Zamjena (COCI18_zamjena) C++17
70 / 70
182 ms 9100 KB
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <string>
using namespace std;

int n;
map <string, string> m;
vector <string> a, b;

bool is_number(string s) {
	return (s[0] >= '0' && s[0] <= '9');
}

string find(string s) {
	if (!m.count(s)) return s;
	if (is_number(s)) return s;
	return m[s] = find(m[s]);
}

bool cmp(string x, string y){
	x = find(x);
	y = find(y);
	if (x == y) return true;
	bool nx = is_number(x), ny = is_number(y);
	if (nx && ny) return x == y;
	else if (nx && !ny) m[y] = x;
	else if (!nx && ny) m[x] = y;
	else m[x] = y;
	return true;
}

bool solve() {
	for (int i = 1; i <= n; i++)
		if (!cmp(a[i], b[i])) return false;
	return true;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	a = b = vector <string>(n + 1);
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) cin >> b[i];
	cout << (solve() ? "DA" : "NE") << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 248 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 292 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 420 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 5 ms 760 KB Output is correct
4 Correct 7 ms 888 KB Output is correct
5 Correct 6 ms 760 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1784 KB Output is correct
2 Correct 39 ms 3184 KB Output is correct
3 Correct 70 ms 4828 KB Output is correct
4 Correct 43 ms 5112 KB Output is correct
5 Correct 182 ms 9100 KB Output is correct
6 Correct 118 ms 6108 KB Output is correct