제출 #984095

#제출 시각아이디문제언어결과실행 시간메모리
984095vjudge1순열 (APIO22_perm)C++17
91.33 / 100
3 ms444 KiB
#include <bits/stdc++.h> #include "perm.h" using namespace std; const int N = 200; int node = 0; vector<int> g[N]; int a[N]; int sz[N]; void precalc(int v) { sz[v] = 1; for (int to : g[v]) { precalc(to); sz[v] += sz[to]; } } void add(int v, int x) { a[v] += x; for (int to : g[v]) add(to, x); } void dfs(int v) { int x = (v > 0); for (int to : g[v]) { dfs(to); add(to, x); x += sz[to]; } } vector<int> b; void construct(int v) { sort(g[v].begin(), g[v].end(), [&](int x, int y) { return a[x] > a[y]; }); if (v) b.push_back(a[v]); for (int to : g[v]) construct(to); } vector<int> construct_permutation(long long k) { if (k == 1) return {}; { g[0].clear(); while (node) { g[node].clear(); a[node] = 0; sz[node] = 0; node--; } b.clear(); } g[0].push_back(1); int mx = 63 - __builtin_clzll(k); node = 1; while (node < mx) { g[node].push_back(node + 1); ++node; } k ^= (1ll << mx); vector<pair<int, int>> st; for (int i = 0; i < mx; i++) { if (~k >> i & 1) continue; if (st.empty() || st.back().first + st.back().second < i) st.push_back({i, 1}); else st.back().second++; } for (auto [pos, k] : st) { ++node; k--; g[pos].push_back(node); while (k--) { g[node].push_back(++node); } } precalc(0); dfs(0); construct(0); return b; }

컴파일 시 표준 에러 (stderr) 메시지

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:84:22: warning: operation on 'node' may be undefined [-Wsequence-point]
   84 |    g[node].push_back(++node);
      |                      ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...