# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
249038 | Vladikus004 | Poklon (COCI17_poklon7) | C++14 | 646 ms | 262148 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
const int N = 1000000 + 3;
int n, is_p[N];
string s[N];
vector <pii> q;
string to_str(int x){
string s;
while (x){
s += (x % 2) + '0';
x /= 2;
}
reverse(all(s));
return s;
}
bool bigger(string &s, string &t){
if (s.size() > t.size()) return true;
if (t.size() > s.size()) return false;
for (int i = 0; i < s.size(); i++){
if (s[i] > t[i]) return true;
if (s[i] < t[i]) return false;
}
return false;
}
void dfs(int x){
if (q[x].first > 0){
dfs(q[x].first - 1);
}
if (q[x].second > 0){
dfs(q[x].second - 1);
}
string s1, s2;
if (q[x].first > 0) s1 = s[q[x].first - 1];
else s1 = to_str(-q[x].first);
if (q[x].second > 0) s2 = s[q[x].second - 1];
else s2 = to_str(-q[x].second);
// cout << x << " : " << s1 << " " << s2 << " - ";
if (bigger(s1, s2)) s[x] = s1 ;
else s[x] = s2;
s[x] += '0';
// cout << s[x] << "\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif // LOCAL
cin >> n;
q.resize(n);
for (int i = 0; i < n; i++){
cin >> q[i].first >> q[i].second;
if (q[i].first > 0){
is_p[q[i].first - 1] = 1;
}
if (q[i].second > 0){
is_p[q[i].second - 1] = 1;
}
}
int st = -1;
for (int i = 0; i < n; i++){
if (!is_p[i]){
st = i;
}
}
dfs(st);
cout << s[st];
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |