| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 366261 | wiwiho | Zamjena (COCI18_zamjena) | C++14 | 109 ms | 6892 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define eb emplace_back
#define printv(a, b) {\
bool ps = false;\
for(auto pv : a){\
if(ps) b << ' '; ps = true;\
b << pv;\
}\
b << "\n";\
}
using namespace std;
map<string, int> id;
int ts = 1;
void read(vector<int>& a){
for(int i = 0; i < a.size(); i++){
string s;
cin >> s;
if('0' <= s[0] && s[0] <= '9'){
a[i] = -stoi(s);
continue;
}
if(id.find(s) == id.end()) id[s] = ++ts;
a[i] = id[s];
}
}
vector<vector<int>> g;
vector<int> v;
void dfs(int now, int tv){
v[now] = tv;
for(int i : g[now]){
if(v[i] != -1) continue;
dfs(i, tv);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
map<string, int> id;
vector<int> a(n), b(n);
read(a);
read(b);
//printv(a, cerr);
//printv(b, cerr);
g.resize(ts + 1);
for(int i = 0; i < n; i++){
if(a[i] < 0 || b[i] < 0) continue;
g[a[i]].eb(b[i]);
g[b[i]].eb(a[i]);
}
v.resize(ts + 1, -1);
for(int i = 0; i < n; i++){
//cerr << i << " ";
//printv(v, cerr);
if(a[i] < 0 && b[i] < 0){
if(a[i] != b[i]) return cout << "NE\n", 0;
continue;
}
if(a[i] < 0){
if(v[b[i]] != -1){
//cerr << i << " " << v[b[i]] << " " << -a[i] << "\n";
if(v[b[i]] != -a[i]) return cout << "NE\n", 0;
continue;
}
dfs(b[i], -a[i]);
}
if(b[i] < 0){
if(v[a[i]] != -1){
if(v[a[i]] != -b[i]) return cout << "NE\n", 0;
//cerr << i << " " << v[a[i]] << " " << -b[i] << "\n";
continue;
}
dfs(a[i], -b[i]);
}
}
cout << "DA\n";
return 0;
}
컴파일 시 표준 에러 (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... | ||||
