Submission #899609

#TimeUsernameProblemLanguageResultExecution timeMemory
899609marvinthangCoreputer (IOI23_coreputer)C++17
100 / 100
1 ms596 KiB
#include "coreputer.h" #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define BIT(x, i) ((x) >> (i) & 1) #define MASK(i) (1LL << (i)) #define left ___left #define right ___right #define ALL(v) (v).begin(), (v).end() #define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i) #define REPD(i, n) for (int i = (n); i-- > 0; ) #define FOR(i, a, b) for (int _b = (b), i = (a); i < _b; ++i) #define FORD(i, b, a) for (int _a = (a), i = (b); i-- > _a; ) #define FORE(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORDE(i, b, a) for (int i = (b), _a = (a); i >= _a; --i) #define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u) #define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u) #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } template <class U, class V> scan_op(pair <U, V>) { return in >> u.fi >> u.se; } template <class T> scan_op(vector <T>) { for (T &x: u) in >> x; return in; } template <class U, class V> print_op(pair <U, V>) { return out << "(" << u.fi << ", " << u.se << ")"; } template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")"; else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); } template <class ...U> print_op(tuple <U...>) { return print_tuple_utils<0, tuple <U...>> (out, u); } template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream &>::type operator << (ostream &out, const Con &u) { out << "{"; for (auto it = u.begin(); it != u.end(); ++it) out << (it == u.begin() ? "" : ", ") << *it; return out << "}"; } vector <int> malfunctioning_cores(int N) { vector <int> f(N); auto ask = [&] { vector <int> v; REP(i, N) if (f[i]) v.push_back(i); if (v.empty()) return -1; if (v.size() == N) return 1; return run_diagnostic(v); }; int l = 1, r = N - 1; bool eq = false; while (l <= r) { int m = l + r >> 1; REP(i, N) f[i] = i < m; int k = ask(); eq |= !k; if (k <= 0) l = m + 1; else r = m - 1; } vector <int> res(N, 0); res[r] = 1; REP(i, N) f[i] = (i < r); if (r == N - 1) { if (!eq) return res; REP(i, N - 2) { f[i] = 0; if (ask() < 0) { res[i] = 1; return res; } f[i] = 1; } res[N - 2] = 1; return res; } if (eq) { int cnt = -1; REP(i, r) { f[i] = 0; if (ask() < 0) { res[i] = 1; ++cnt; } f[i] = 1; } FOR(i, r + 1, N - 1) { f[i] = 1; if (ask() > 0) { res[i] = 1; --cnt; } f[i] = 0; } if (cnt) res[N - 1] = 1; return res; } int cnt = 0; f[r] = 1; REP(i, r) { f[i] = 0; if (ask() < 0) { res[i] = 1; ++cnt; } f[i] = 1; } f[r] = 0; FOR(i, r + 1, N - 1) { f[i] = 1; if (ask() > 0) { res[i] = 1; --cnt; } f[i] = 0; } if (cnt) res[N - 1] = 1; return res; }

Compilation message (stderr)

coreputer.cpp: In lambda function:
coreputer.cpp:36:16: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |   if (v.size() == N) return 1;
      |       ~~~~~~~~~^~~~
coreputer.cpp: In function 'std::vector<int> malfunctioning_cores(int)':
coreputer.cpp:42:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |   int m = l + r >> 1;
      |           ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...