# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
472209 |
2021-09-13T09:22:08 Z |
_L__ |
Zamjena (COCI18_zamjena) |
C++17 |
|
39 ms |
12120 KB |
// This code is written by _L__
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl '\n'
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update>;
#define F_word ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
typedef long long ll;
typedef long double ld;
const ll mod = 1e9+7, N = 1e5+30, INF = 1e18;
const ld E = 1e-6;
#define ff first
#define ss second
bool an_int(string s){
return (s[0] >= '1' && s[0] <= '9');
}
bool a_word(string s){
return (s[0] >= 'a' && s[0] <= 'z');
}
vector<int> G[N];
set<int> st;
bool vis[N];
int n; vector<string> v(N), x(N);
void dfs(int node){
vis[node] = 1;
if(node > n){
int idx = node-n;
if(an_int(x[idx])){
ll c = 0;
for(int i = 0; i < x[idx].size(); ++i){
c*=10;
c += x[idx][i]-'0';
}
st.insert(c);
}
} else {
if(an_int(v[node])){
ll c = 0;
for(int i = 0; i < v[node].size(); ++i){
c *= 10;
c += v[node][0]-'0';
}
st.insert(c);
}
}
for(auto i: G[node]){
if(!(vis[i])) dfs(i);
}
}
int main(void){
F_word;
cin >> n;
map<string, vector<int>> mp;
for(int i = 1; i <= n; ++i){
cin >> v[i]; mp[v[i]].push_back(i);
}
for(int i = 1; i <= n; ++i){
cin >> x[i]; mp[x[i]].push_back(n+i);
}
for(int i = 1; i <= n; ++i){
G[i].push_back(n+i);
if(an_int(v[i])) continue;
for(auto c: mp[v[i]]){
if(c == i) continue;
G[i].push_back(c);
}
}
for(int i = 1; i <= n; ++i){
G[n+i].push_back(i);
if(an_int(x[i])) continue;
for(auto c: mp[x[i]]){
if(c == n+i) continue;
G[n+i].push_back(c);
}
}
bool y = 1;
for(int i = 1; i <= 2*n; ++i){
if(!(vis[i])){
st.clear();
dfs(i);
if(st.size() >= 2){y=0;break;}
}
}
cout << (y? "DA\n": "NE\n");
}
Compilation message
zamjena.cpp: In function 'void dfs(int)':
zamjena.cpp:32:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i = 0; i < x[idx].size(); ++i){
| ~~^~~~~~~~~~~~~~~
zamjena.cpp:41:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i = 0; i < v[node].size(); ++i){
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8908 KB |
Output is correct |
2 |
Correct |
5 ms |
8908 KB |
Output is correct |
3 |
Correct |
6 ms |
8908 KB |
Output is correct |
4 |
Correct |
5 ms |
8908 KB |
Output is correct |
5 |
Correct |
5 ms |
8908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8888 KB |
Output is correct |
2 |
Correct |
5 ms |
8908 KB |
Output is correct |
3 |
Correct |
6 ms |
8908 KB |
Output is correct |
4 |
Correct |
5 ms |
8908 KB |
Output is correct |
5 |
Correct |
5 ms |
8908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8908 KB |
Output is correct |
2 |
Incorrect |
6 ms |
8908 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9164 KB |
Output is correct |
2 |
Incorrect |
8 ms |
9036 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
11212 KB |
Output is correct |
2 |
Incorrect |
39 ms |
12120 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |