# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
621133 |
2022-08-03T12:47:33 Z |
Elnady |
Zamjena (COCI18_zamjena) |
C++17 |
|
197 ms |
15728 KB |
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define all(pr1) pr1.begin(),pr1.end()
#define alr(pr1) pr1.rbegin(),pr1.rend()
#define CEIL(pr1, pr2) (pr1 + pr2 - 1) / pr2
#define IOS std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define RT(s) return cout<<s,0
#define sz(s) (long long)(s.size())
const long long N = 2e5 + 9, M = 1e9 + 9, MOD = 1e9 + 7, OO = 0x3f3f3f3f, MAX = 2147483647, LOO = 0x3f3f3f3f3f3f3f3f;
bool isNum(char c)
{
if (c >= '0' && c <= '9')
return 1;
return 0;
}
int32_t main()
{
IOS;
int n;
cin >> n;
vector<string> a(n), b(n);
multiset <pair<string, string>> st;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
bool can = 1;
map<string, int> mp;
map<string, vector<string>> mp2;
for (int i = 0; i < n && can; i++)
{
bool aa = isNum(a[i][0]);
bool bb = isNum(b[i][0]);
if (aa && bb)
{
if (a[i] != b[i])
can = 0;
}
else if (aa && !bb)
st.insert({ a[i],b[i] });
else if (!aa && bb)
st.insert({ b[i],a[i] });
else
{
mp2[a[i]].push_back(b[i]);
mp2[b[i]].push_back(a[i]);
}
}
while (can && sz(st))
{
pair<string, string> xx = *(st.begin());
st.erase(st.begin());
int x = stoi(xx.first);
string y = xx.second;
if (mp.find(y) != mp.end() && mp[y] != x)
can = 0;
else
{
mp[y] = x;
for (int i = sz(mp2[y]) - 1; i >= 0; i--)
{
string z = to_string(x);
st.insert({ z, mp2[y].back() });
mp2[y].pop_back();
}
}
}
cout << (can ? "DA\n" : "NE\n");
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
580 KB |
Output is correct |
2 |
Correct |
3 ms |
468 KB |
Output is correct |
3 |
Correct |
7 ms |
1048 KB |
Output is correct |
4 |
Correct |
8 ms |
1108 KB |
Output is correct |
5 |
Correct |
8 ms |
1108 KB |
Output is correct |
6 |
Correct |
8 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
3016 KB |
Output is correct |
2 |
Correct |
62 ms |
5560 KB |
Output is correct |
3 |
Correct |
68 ms |
8344 KB |
Output is correct |
4 |
Correct |
112 ms |
10156 KB |
Output is correct |
5 |
Correct |
197 ms |
15728 KB |
Output is correct |
6 |
Correct |
165 ms |
11696 KB |
Output is correct |