# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1276145 | chanhchuong123 | Zamjena (COCI18_zamjena) | C++20 | 89 ms | 15156 KiB |
#include<bits/stdc++.h>
using namespace std;
const bool multiTest = false;
#define task "C"
#define fi first
#define se second
#define MASK(i) (1LL << (i))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define BIT(mask, i) ((mask) >> (i) & 1)
template<typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) a = b; else return 0; return 1;
}
template<typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) a = b; else return 0; return 1;
}
const int MAX = 50050;
int N;
string s[2][MAX];
map<string, bool> used;
map<string, vector<string>> adj;
bool isNumber(const string &s) {
return '0' <= s[0] && s[0] <= '9';
}
void fix(string &s) {
reverse(all(s)); while (s.size() && s.back() == '0') s.pop_back();
if (s.empty()) s.push_back('0');
reverse(all(s));
}
void dfs(string u, string value) {
if (used[u]) return; used[u] = true;
if (isNumber(u)) {
if (u != value) {
cout << "NE";
exit(0);
}
}
for (string v: adj[u]) {
dfs(v, value);
}
}
void process(void) {
cin >> N;
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < N; ++j) {
cin >> s[i][j];
if (isNumber(s[i][j])) fix(s[i][j]);
}
}
for (int i = 0; i < N; ++i) {
if (isNumber(s[0][i]) && isNumber(s[1][i])) {
if (s[0][i] != s[1][i]) {
cout << "NE";
return;
}
}
adj[s[0][i]].push_back(s[1][i]);
adj[s[1][i]].push_back(s[0][i]);
}
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < N; ++j) if (isNumber(s[i][j])) {
dfs(s[i][j], s[i][j]);
}
}
cout << "DA";
}
int main(void) {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int nTest = 1; if (multiTest) cin >> nTest;
while (nTest--) {
process();
}
return 0;
}
Compilation message (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... |