Submission #322223

#TimeUsernameProblemLanguageResultExecution timeMemory
322223dolphingarlicSwap (BOI16_swap)C++14
48 / 100
220 ms262144 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; int a[1 << 18]; vector<int> dp[1 << 18][18][2], tmp1, tmp2; void merge(vector<int> &ret, vector<int> &l, vector<int> &r) { for (int i = 0, j = 1; i < l.size(); i += j, j <<= 1) { for (int k = i; k < i + j; k++) ret.push_back(l[k]); for (int k = i; k < i + j; k++) ret.push_back(r[k]); } } int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", a + i); int orig = n; while (__builtin_popcount(n + 1) != 1) a[++n] = n; for (int node = n; node; node--) { for (int i = 0; node >> i; i++) for (int j : {0, 1}) { if (!(((node >> i + 1) << 1) + j)) continue; if (node * 2 > n) dp[node][i][j] = {a[((node >> i + 1) << 1) + j]}; else { int mn = min({a[((node >> i + 1) << 1) + j], a[2 * node], a[2 * node + 1]}); if (mn == a[((node >> i + 1) << 1) + j]) { dp[node][i][j] = {a[((node >> i + 1) << 1) + j]}; merge(dp[node][i][j], dp[2 * node][0][0], dp[2 * node + 1][0][1]); } else if (mn == a[2 * node]) { dp[node][i][j] = {a[2 * node]}; merge(dp[node][i][j], dp[2 * node][i + 1][j], dp[2 * node + 1][0][1]); } else { tmp1 = tmp2 = {a[2 * node + 1]}; merge(tmp1, dp[2 * node][0][0], dp[2 * node + 1][i + 1][j]); merge(tmp2, dp[2 * node][i + 1][j], dp[2 * node + 1][0][0]); dp[node][i][j] = min(tmp1, tmp2); } } } } for (int i = 0; i < orig; i++) printf("%d ", dp[1][0][1][i]); return 0; }

Compilation message (stderr)

swap.cpp: In function 'void merge(std::vector<int>&, std::vector<int>&, std::vector<int>&)':
swap.cpp:9:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for (int i = 0, j = 1; i < l.size(); i += j, j <<= 1) {
      |                            ~~^~~~~~~~~~
swap.cpp: In function 'int main()':
swap.cpp:20:46: warning: operation on 'n' may be undefined [-Wsequence-point]
   20 |     while (__builtin_popcount(n + 1) != 1) a[++n] = n;
      |                                              ^~~
swap.cpp:20:46: warning: operation on 'n' may be undefined [-Wsequence-point]
swap.cpp:24:31: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   24 |             if (!(((node >> i + 1) << 1) + j)) continue;
      |                             ~~^~~
swap.cpp:26:63: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   26 |             if (node * 2 > n) dp[node][i][j] = {a[((node >> i + 1) << 1) + j]};
      |                                                             ~~^~~
swap.cpp:28:45: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |                 int mn = min({a[((node >> i + 1) << 1) + j], a[2 * node], a[2 * node + 1]});
      |                                           ~~^~~
swap.cpp:29:41: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |                 if (mn == a[((node >> i + 1) << 1) + j]) {
      |                                       ~~^~~
swap.cpp:30:53: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |                     dp[node][i][j] = {a[((node >> i + 1) << 1) + j]};
      |                                                   ~~^~~
swap.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
swap.cpp:18:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |     for (int i = 1; i <= n; i++) scanf("%d", a + i);
      |                                  ~~~~~^~~~~~~~~~~~~
#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...