답안 #405340

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
405340 2021-05-16T09:13:11 Z Aryan_Raina Poklon (COCI17_poklon7) C++14
120 / 120
801 ms 221680 KB
#include <bits/stdc++.h>
using namespace std; 
 
#define int int64_t
#define ld long double
#define ar array
 
const int INF = 1e17;
const int MOD = 1e9+7;
 
int32_t main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
 
   int N; cin >> N;
   vector<ar<int,2>> adj(N);
   for (auto &i : adj) {
      cin >> i[0] >> i[1];
      if (i[0] > 0) --i[0];
      if (i[1] > 0) --i[1];
   }

   vector<string> remdi;
   function<int(int)> dfs = [&](int u)->int {
      if (u < 0) {
         remdi.push_back("");
         for (int i = -u; i; i >>= 1) remdi.back() += '0' + (i & 1);
         reverse(remdi.back().begin(), remdi.back().end());
         return (int) remdi.size() - 1;
      }

      int lc = dfs(adj[u][0]), rc = dfs(adj[u][1]), ans = lc;
      if (remdi[lc].size() == remdi[rc].size()) {
         for (int i = 0; i < remdi[lc].size(); i++) {
            if (remdi[lc][i] ^ remdi[rc][i]) {
               ans = (remdi[lc][i] - '0') ? lc : rc; 
               break;
            }
         }
      } else {
         ans = (remdi[lc].size() > remdi[rc].size()) ? lc : rc;
      }

      remdi[ans] += '0';
      return ans;
   };

   cout << remdi[dfs(0)] << '\n';
}  

Compilation message

poklon.cpp: In lambda function:
poklon.cpp:34:28: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |          for (int i = 0; i < remdi[lc].size(); i++) {
      |                          ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 324 KB Output is correct
11 Correct 10 ms 2120 KB Output is correct
12 Correct 10 ms 2116 KB Output is correct
13 Correct 39 ms 9252 KB Output is correct
14 Correct 77 ms 18456 KB Output is correct
15 Correct 75 ms 12088 KB Output is correct
16 Correct 288 ms 53640 KB Output is correct
17 Correct 653 ms 114236 KB Output is correct
18 Correct 640 ms 120624 KB Output is correct
19 Correct 800 ms 123308 KB Output is correct
20 Correct 801 ms 221680 KB Output is correct