답안 #681747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
681747 2023-01-14T03:13:38 Z penguin133 Zamjena (COCI18_zamjena) C++17
70 / 70
91 ms 10200 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif

int n;
string s[50005], t[50005];
map<string, vector<int> > mp;
int stuf[50005], val;
bool die = 0;

void dfs(string bruh){
	for(auto i : mp[bruh]){
		if(!stuf[i])stuf[i] = val;
		else {
			if(stuf[i] != val)die = 1;
			continue;
		}
		if(s[i] != bruh && (s[i][0] < '0' || s[i][0] > '9'))dfs(s[i]);
		if(t[i] != bruh && (t[i][0] < '0' || t[i][0] > '9'))dfs(t[i]);
	}
}

void solve(){
	cin >> n;
	for(int i=1;i<=n;i++)cin >> s[i];
	for(int i=1;i<=n;i++)cin >> t[i];
	for(int i=1;i<=n;i++){
		if(s[i][0] >= '0' && s[i][0] <= '9')continue;
		mp[s[i]].push_back(i);
	}
	for(int i=1;i<=n;i++){
		if(t[i][0] >= '0' && t[i][0] <= '9')continue;
		mp[t[i]].push_back(i);
	}
	for(int i=1;i<=n;i++){
		if(s[i][0] < '0' || s[i][0] > '9'){
			if((t[i][0] >= '0' && t[i][0] <= '9')){
				val = 0;
				for(auto j : t[i])val = val * 10 + (j - '0');
				dfs(s[i]);
			}
			else if(stuf[i]){
				val = stuf[i];
				dfs(s[i]);
			}
		}
		if(t[i][0] < '0' || t[i][0] > '9'){
			if(s[i][0] >= '0' && s[i][0] <= '9'){
				val = 0;
				for(auto j : s[i])val = val * 10 + (j - '0');
				dfs(t[i]);
			}
			else if(stuf[i]){
				val = stuf[i];
				dfs(t[i]);
			}
		}
		else if((s[i][0] >= '0' && s[i][0] <= '9') && (t[i][0] >= '0' && t[i][0] <= '9')){
			int val2 = 0, val3 = 0;
			for(auto j : s[i])val2 = val2 * 10 + (j - '0');
			for(auto j : t[i])val3=  val3 * 10 + (j - '0');
			if(val2 != val3)die = 1;
		}
	}
	cout << (die ? "NE" : "DA");
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Compilation message

zamjena.cpp:76:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   76 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3456 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 2 ms 3456 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 3 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3668 KB Output is correct
2 Correct 2 ms 3540 KB Output is correct
3 Correct 6 ms 3796 KB Output is correct
4 Correct 5 ms 3796 KB Output is correct
5 Correct 5 ms 3796 KB Output is correct
6 Correct 5 ms 3668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 5004 KB Output is correct
2 Correct 25 ms 5588 KB Output is correct
3 Correct 47 ms 7112 KB Output is correct
4 Correct 53 ms 7692 KB Output is correct
5 Correct 91 ms 10200 KB Output is correct
6 Correct 70 ms 7756 KB Output is correct