# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
197028 | quocnguyen1012 | Zamjena (COCI18_zamjena) | C++14 | 218 ms | 23288 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
struct DSU
{
vector<int> lab;
void init(int n)
{
lab.resize(n + 5);
fill(begin(lab), end(lab), -1);
}
int finds(int u)
{
if (lab[u] < 0) return u;
return lab[u] = finds(lab[u]);
}
void merges(int u, int v)
{
u = finds(u); v = finds(v);
if (u == v) return;
if (lab[v] < lab[u]) swap(u, v);
lab[u] += lab[v];
lab[v] = u;
}
}dsu;
map<string, int> ma;
int cnt = 0;
map<string, bool> ok;
string a[maxn], b[maxn];
int N;
string val[maxn];
bool isdigit(char x)
{
return ('0' <= x && x <= '9');
}
signed main(void)
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen("A.INP", "r")){
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
}
int cnt = 0;
cin >> N;
for (int i = 1; i <= N; ++i){
cin >> a[i];
if (!isdigit(a[i][0])){
if (ma[a[i]] == 0)ma[a[i]] = ++cnt;
}
}
for (int i = 1; i <= N; ++i){
cin >> b[i];
if (!isdigit(b[i][0])){
if (ma[b[i]] == 0)ma[b[i]] = ++cnt;
}
}
//for (int i = 1; i <= N; ++i)cerr << isdigit(a[i][0]) << ' ' << isdigit(b[i][0]) << '\n';
//return 0;
dsu.init(cnt);
for (int i = 1; i <= N; ++i){
if (isdigit(a[i][0]) == 0 && isdigit(b[i][0]) == 0){
dsu.merges(ma[a[i]], ma[b[i]]);
//cerr << i << '\n';
}
}
for (int i = 1; i <= N; ++i){
if (isdigit(a[i][0]) && isdigit(b[i][0])){
//cerr << i << '\n';
if (a[i] != b[i]){
cout << "NE";
return 0;
}
}
else if (isdigit(a[i][0])){
val[dsu.finds(ma[b[i]])] = a[i];
//cerr << i << '\n';
}
else if (isdigit(b[i][0])){
val[dsu.finds(ma[a[i]])] = b[i];
}
}
for (int i = 1; i <= N; ++i){
if (isdigit(a[i][0]) && isdigit(b[i][0])){
if (a[i] != b[i]){
cout << "NE";
return 0;
}
}
else if (isdigit(a[i][0])){
if (val[dsu.finds(ma[b[i]])] != a[i]){
cout << "NE";
//cerr << i;
return 0;
}
}
else if (isdigit(b[i][0])){
if (val[dsu.finds(ma[a[i]])] != b[i]){
cout << "NE";
return 0;
}
}
else{
if (val[dsu.finds(ma[a[i]])] != val[dsu.finds(ma[b[i]])]){
cout << "NE";
return 0;
}
}
}
cout << "DA";
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |