# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
82266 |
2018-10-29T17:03:21 Z |
Milki |
Zamjena (COCI18_zamjena) |
C++14 |
|
116 ms |
16348 KB |
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
typedef long long ll;
typedef pair<int, int> point;
const int MAXN = 5e4 + 5;
unordered_map<string, string> val;
unordered_map<string, vector<string> > isti;
int n;
string a[MAXN], b[MAXN];
void postavi(string x, string value){
string realVal = val[x];
if(realVal != ""){
if(realVal == value) return;
else{
cout << "NE\n";
exit(0);
}
}
val[x] = value;
for(auto it : isti[x]){
postavi(it, value);
}
isti[x].clear();
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n;
REP(i, n) cin >> a[i];
REP(i, n) cin >> b[i];
REP(i, n){
if(a[i] == b[i]) continue;
if(a[i][0] >= '0' && a[i][0] <= '9' && b[i][0] >= '0' && b[i][0] <= '9'){
if(a[i] != b[i]){
cout << "NE\n";
return 0;
}
}
else if( (a[i][0] >= '0' && a[i][0] <= '9') || (b[i][0] >= '0' && b[i][0] <= '9')){
if(a[i][0] >= '0' && a[i][0] <= '9') swap(a[i], b[i]);
string value = val[a[i]];
if(value != "")
if(value != b[i]){
cout << "NE\n";
return 0;
}
val[a[i]] = b[i];
postavi(a[i], b[i]);
}
else{
string val_a = val[a[i]], val_b = val[b[i]];
//cout << val_a _ val_b <<" value\n";
if(val_a == "") {
swap(val_a, val_b);
swap(a[i], b[i]);
}
if(val_a == "" && val_b == ""){
isti[a[i]].pb(b[i]);
isti[b[i]].pb(a[i]);
}
else if(val_a != "" && val_b == ""){
postavi(b[i], val_a);
}
else if(val_a != val_b){
cout << "NE\n";
return 0;
}
}
}
cout << "DA\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3448 KB |
Output is correct |
2 |
Correct |
4 ms |
3604 KB |
Output is correct |
3 |
Correct |
5 ms |
3604 KB |
Output is correct |
4 |
Correct |
4 ms |
3604 KB |
Output is correct |
5 |
Correct |
5 ms |
3604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3604 KB |
Output is correct |
2 |
Incorrect |
4 ms |
3604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3604 KB |
Output is correct |
2 |
Correct |
4 ms |
3604 KB |
Output is correct |
3 |
Correct |
5 ms |
3604 KB |
Output is correct |
4 |
Correct |
4 ms |
3604 KB |
Output is correct |
5 |
Correct |
4 ms |
3636 KB |
Output is correct |
6 |
Correct |
4 ms |
3652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3908 KB |
Output is correct |
2 |
Correct |
7 ms |
3908 KB |
Output is correct |
3 |
Correct |
7 ms |
4204 KB |
Output is correct |
4 |
Correct |
9 ms |
4476 KB |
Output is correct |
5 |
Correct |
10 ms |
4476 KB |
Output is correct |
6 |
Correct |
9 ms |
4476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
5244 KB |
Output is correct |
2 |
Correct |
32 ms |
7292 KB |
Output is correct |
3 |
Correct |
48 ms |
9928 KB |
Output is correct |
4 |
Correct |
52 ms |
9928 KB |
Output is correct |
5 |
Correct |
116 ms |
16348 KB |
Output is correct |
6 |
Correct |
63 ms |
16348 KB |
Output is correct |