Submission #460741

# Submission time Handle Problem Language Result Execution time Memory
460741 2021-08-09T09:00:56 Z grt Zamjena (COCI18_zamjena) C++17
14 / 70
30 ms 3112 KB
#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

using namespace std;

using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;

const int nax = 50 * 1000 + 10;
int n;
int a[nax];
vi V[nax];
map<string, int> sc;
int nr;
bool vis[nax];
vi cur;

void dfs(int x) {
	vis[x] = true;
	cur.PB(x);
	for(int nbh : V[x]) if(!vis[nbh]) dfs(nbh);
}


int main() {_
	cin >> n;
	for(int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		if(s[0] >= '0' && s[0] <= '9') {
			int num = atoi(s.c_str());
			a[i] = -num;
		} else {
			if(!sc.count(s)) sc[s] = ++nr;
			a[i] = sc[s];
		}
	}
	for(int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		if(s[0] >= '0' && s[0] <= '9') {
			int num = atoi(s.c_str());
			if(a[i] < 0 && a[i] != -num) {
				cout << "NE";
				return 0;
			}
			a[i] = -num;
		} else {
			if(!sc.count(s)) sc[s] = ++nr;
			if(a[i] > 0) {
				V[sc[s]].PB(a[i]);
				V[a[i]].PB(sc[s]);
			}
		}
	}
	for(int i = 1; i <= nr; ++i) {
		if(!vis[i]) {
			cur.clear();
			dfs(i);
			int last = 0;
			for(int x : cur) {
				if(a[x] < 0) {
					if(last == 0) last = a[x];
					else if(last != a[x]) {
						cout << "NE";
						return 0;
					}
				}
			}
		}
	}
	cout << "DA";
	
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Incorrect 1 ms 1484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Incorrect 1 ms 1500 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1484 KB Output is correct
2 Incorrect 3 ms 1504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2372 KB Output is correct
2 Incorrect 30 ms 3112 KB Output isn't correct
3 Halted 0 ms 0 KB -