제출 #472238

#제출 시각아이디문제언어결과실행 시간메모리
472238_L__Zamjena (COCI18_zamjena)C++14
70 / 70
150 ms18320 KiB
// This code is written by _L__ #include <bits/stdc++.h> using namespace std; #define endl '\n' #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+300, INF = 1e18; const ld E = 1e-6; bool an_int(string s){ return (s[0] >= '0' && s[0] <= '9'); } bool a_word(string s){ return (s[0] >= 'a' && s[0] <= 'z'); } vector<int> G[N+4];bool vis[N+3];int n; set<int> st; vector<string> v(N+3), x(N+5); void dfs(int node){ if(vis[node]) return; vis[node] = 1; if(node>n && an_int(x[node-n])){ ll c = 0; for(auto b: x[node-n]){c*=10;c+=(b-'0');} st.insert(c); } else if(an_int(v[node])){ ll c = 0; for(auto b: v[node]){c*=10;c+=(b-'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"); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...