답안 #251391

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251391 2020-07-21T05:36:36 Z zahra__d Zamjena (COCI18_zamjena) C++14
70 / 70
159 ms 17912 KB
# include<bits/stdc++.h>
# include<ext/pb_ds/assoc_container.hpp>
# include<ext/pb_ds/tree_policy.hpp>
# pragma GCC optimize ("Ofast")
# pragma GCC optimize ("unroll-loops")
# pragma GCC optimize ("Ofast")

using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

# define int long long
# define S second
# define F first
# define kill(x) return(cout << x << '\n', 0LL)
# define debug(x) cerr<< #x << " = " << (x) << endl
# define ddebug(x, y) cerr<< #x << " = " << (x)  << ", " << #y << " = " << (y) << endl
# define tdebug(x, y, z) cerr<< #x << " = " << (x)  << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl
# define bin(x) cerr<< #x << " : " << bitset<7>(x) << endl
# define sz(s) (int)s.size()
# define sq(x) (x) * (x)
# define PB(x) push_back(x)
# define smax(x, y) (x) = max((x), (y))
# define smin(x, y) (x) = min((x), (y))
# define all(x) x.begin(), x.end()
# define SP fixed << setprecision(10)
# define uop(x, y) pii(min(x, y), max(x, y))
# define MP(x, y) make_pair(x, y)

const int MAXN = 100 * 1000;
string a[MAXN], b[MAXN], s[MAXN];
map <string, int> mp;
int cnt;
bool mark[MAXN];
vector <int> adj[MAXN];

int dfs(int v)
{
	mark[v] = true;

	int res = 0;
	if (s[v][0] <= '9' && s[v][0] >= '0')
		res ++;

	for (int u : adj[v])
		if (!mark[u])
			res += dfs(u);

	return res;
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n;
	cin >> n;
	for (int i = 0; i < n; i ++)
	{
		cin >> a[i];
		if (!mp.count(a[i]))
		{
			s[cnt] = a[i];
			mp[a[i]] = cnt ++;
		}
	}
	for (int i = 0; i < n; i ++)
	{
		cin >> b[i];
		if (!mp.count(b[i]))
		{
			s[cnt] = b[i];
			mp[b[i]] = cnt ++;
		}

		adj[mp[b[i]]].PB(mp[a[i]]);
		adj[mp[a[i]]].PB(mp[b[i]]);
	}

	for (int i = 0; i < cnt; i ++)
		if (!mark[i])
		{
			if (dfs(i) > 1)
				kill("NE");
		}

	cout << "DA" << endl;

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12032 KB Output is correct
2 Correct 7 ms 12032 KB Output is correct
3 Correct 7 ms 12032 KB Output is correct
4 Correct 7 ms 12032 KB Output is correct
5 Correct 6 ms 12032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12032 KB Output is correct
2 Correct 8 ms 12032 KB Output is correct
3 Correct 7 ms 12032 KB Output is correct
4 Correct 7 ms 12032 KB Output is correct
5 Correct 7 ms 12032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12032 KB Output is correct
2 Correct 7 ms 12032 KB Output is correct
3 Correct 7 ms 12032 KB Output is correct
4 Correct 7 ms 12032 KB Output is correct
5 Correct 7 ms 12032 KB Output is correct
6 Correct 7 ms 12032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12160 KB Output is correct
2 Correct 8 ms 12160 KB Output is correct
3 Correct 13 ms 12416 KB Output is correct
4 Correct 12 ms 12416 KB Output is correct
5 Correct 13 ms 12416 KB Output is correct
6 Correct 13 ms 12288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 12992 KB Output is correct
2 Correct 46 ms 13944 KB Output is correct
3 Correct 77 ms 15224 KB Output is correct
4 Correct 101 ms 15864 KB Output is correct
5 Correct 159 ms 17912 KB Output is correct
6 Correct 113 ms 15608 KB Output is correct