Submission #1048501

#TimeUsernameProblemLanguageResultExecution timeMemory
1048501becaidoAncient Books (IOI17_books)C++17
50 / 100
73 ms35644 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,popcnt,sse4,abm") #include <bits/stdc++.h> using namespace std; #ifdef WAIMAI #include "grader.cpp" #else #include "books.h" #endif #ifdef WAIMAI #define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE) void dout() {cout << '\n';} template<typename T, typename...U> void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);} #else #define debug(...) 7122 #endif #define ll long long #define Waimai ios::sync_with_stdio(false), cin.tie(0) #define FOR(x,a,b) for (int x = a, I = b; x <= I; x++) #define pb emplace_back #define F first #define S second const int SIZE = 1e6 + 5; int n; int p[SIZE]; int d[SIZE], in[SIZE], out[SIZE]; int add_in[SIZE], add_out[SIZE], add_d[SIZE]; ll minimum_walk(vector<int> p_, int s) { n = p_.size(); s++; FOR (i, 1, n) { p[i] = p_[i - 1] + 1; in[i] = out[i] = 0; add_in[i] = add_out[i] = add_d[i] = 0; } FOR (i, 1, n) { if (i < p[i]) { out[i]++, out[p[i]]--; in[i + 1]++, in[p[i] + 1]--; d[i]++, d[p[i]]--; } else { out[p[i] + 1]++, out[i + 1]--; in[p[i]]++, in[i]--; d[p[i]]++, d[i]--; } } FOR (i, 1, n) { in[i] += in[i - 1]; out[i] += out[i - 1]; d[i] += d[i - 1]; debug(i, in[i], out[i]); } while (n > 1 && d[n - 1] == 0) n--; if (n == 1) return 0; vector<int> v[2]; FOR (i, 1, n) { int delta = out[i] - in[i]; while (delta > 0) { if (v[1].size()) { int l = v[1].back(); v[1].pop_back(); add_out[l]++, add_out[i]--; add_in[l + 1]++, add_in[i + 1]--; add_d[l]++, add_d[i]--; } else { v[0].pb(i); } delta--; } while (delta < 0) { if (v[0].size()) { int l = v[0].back(); v[0].pop_back(); add_in[l]++, add_in[i]--; add_out[l + 1]++, add_out[i + 1]--; add_d[l]++, add_d[i]--; } else { v[1].pb(i); } delta++; } } assert(v[0].size() == 0 && v[1].size() == 0); FOR (i, 1, n) { add_in[i] += add_in[i - 1], in[i] += add_in[i]; add_out[i] += add_out[i - 1], out[i] += add_out[i]; add_d[i] += add_d[i - 1], d[i] += add_d[i]; } ll ans = 0; FOR (i, 1, n) { debug(i, in[i], out[i], d[i]); ans += out[i]; if (i < n && d[i] == 0) ans += 2; } return ans; } /* in1 4 0 0 2 3 1 out1 6 */

Compilation message (stderr)

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:18:20: warning: statement has no effect [-Wunused-value]
   18 | #define debug(...) 7122
      |                    ^~~~
books.cpp:58:9: note: in expansion of macro 'debug'
   58 |         debug(i, in[i], out[i]);
      |         ^~~~~
books.cpp:18:20: warning: statement has no effect [-Wunused-value]
   18 | #define debug(...) 7122
      |                    ^~~~
books.cpp:98:9: note: in expansion of macro 'debug'
   98 |         debug(i, in[i], out[i], d[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...