Submission #317199

#TimeUsernameProblemLanguageResultExecution timeMemory
317199Kevin_Zhang_TWHidden Sequence (info1cup18_hidden)C++17
34 / 100
10 ms384 KiB
#include<bits/stdc++.h> #define pb emplace_back #define AI(i) begin(i), end(i) using namespace std; using ll = long long; #ifdef KEV #define DE(args...) kout("[ " + string(#args) + " ] : ", args) void kout() { cerr << endl; } template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); } void debug(auto L, auto R) { while (L != R) cerr << *L << " \n"[next(L) == R], ++L; } vector<int> ans{1,0,0,0,0,0,0,0,1,1,0}; bool isSubsequence(vector<int> a) { for (int i = 0, j = 0;i < a.size();++i) { while (j < ans.size() && ans[j] != a[i]) ++j; if (j == ans.size()) return false; ++j; } return true; } #else #include "grader.h" #define debug(...) 0 #define DE(...) 0 #endif const int MAX_N = 300010; const vector<int> zero{0}, one{1}; int n; bool query(vector<int> a) { if (a.size() > n) return false; return isSubsequence(a); } vector<int> operator + (vector<int> a, vector<int> b) { a.insert(end(a), AI(b)); return a; } vector<int> findSequence(int _n) { n = _n; DE(n); vector<int> Z, O, ans; while (true) { bool go = true; if (query(Z + zero)) Z.pb(0); else go = false; if (query(O + one)) O.pb(1); else go = false; if (!go) break; } DE(O.size(), Z.size()); if (query(O + one)) { while (O.size() + Z.size() < n) O.pb(1); } else { while (O.size() + Z.size() < n) Z.pb(0); } if (Z.empty() || O.empty()) return Z.empty() ? O : Z; vector<int> cnt(n+1); DE(__LINE__); // insert into zeroes if (Z.size() < O.size()) { int zs = Z.size(); for (int i = 0;i <= Z.size();++i) { vector<int> ad; while (query(vector<int>(i, 0) + ad + one + vector<int>(zs-i, 0))) ++cnt[i], ad.pb(1); } for (int i = 0;i <= Z.size();++i) { while (cnt[i]--) ans.pb(1); if (i < Z.size()) ans.pb(0); } } else { int zs = O.size(); DE(zs); for (int i = 0;i <= O.size();++i) { vector<int> ad; while (query(vector<int>(i, 1) + ad + zero + vector<int>(zs-i, 1))) ++cnt[i], ad.pb(0); } for (int i = 0;i <= O.size();++i) { while (cnt[i]--) ans.pb(0); if (i < O.size()) ans.pb(1); } } return ans; } #ifdef KEV int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0); vector<int> res = findSequence(ans.size()); if (res == ans) cerr << "AC!\n"; else { cerr << "WA\n"; debug(AI(res)); cerr << "Should be\n"; debug(AI(ans)); } } #endif

Compilation message (stderr)

hidden.cpp: In function 'bool query(std::vector<int>)':
hidden.cpp:31:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |  if (a.size() > n) return false;
      |      ~~~~~~~~~^~~
hidden.cpp: In function 'std::vector<int> findSequence(int)':
hidden.cpp:25:17: warning: statement has no effect [-Wunused-value]
   25 | #define DE(...) 0
      |                 ^
hidden.cpp:41:2: note: in expansion of macro 'DE'
   41 |  DE(n);
      |  ^~
hidden.cpp:25:17: warning: statement has no effect [-Wunused-value]
   25 | #define DE(...) 0
      |                 ^
hidden.cpp:55:2: note: in expansion of macro 'DE'
   55 |  DE(O.size(), Z.size());
      |  ^~
hidden.cpp:58:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   58 |   while (O.size() + Z.size() < n)
      |          ~~~~~~~~~~~~~~~~~~~~^~~
hidden.cpp:62:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   62 |   while (O.size() + Z.size() < n)
      |          ~~~~~~~~~~~~~~~~~~~~^~~
hidden.cpp:25:17: warning: statement has no effect [-Wunused-value]
   25 | #define DE(...) 0
      |                 ^
hidden.cpp:70:2: note: in expansion of macro 'DE'
   70 |  DE(__LINE__);
      |  ^~
hidden.cpp:74:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |   for (int i = 0;i <= Z.size();++i) {
      |                  ~~^~~~~~~~~~~
hidden.cpp:79:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |   for (int i = 0;i <= Z.size();++i) {
      |                  ~~^~~~~~~~~~~
hidden.cpp:82:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |    if (i < Z.size())
      |        ~~^~~~~~~~~~
hidden.cpp:25:17: warning: statement has no effect [-Wunused-value]
   25 | #define DE(...) 0
      |                 ^
hidden.cpp:88:3: note: in expansion of macro 'DE'
   88 |   DE(zs);
      |   ^~
hidden.cpp:89:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |   for (int i = 0;i <= O.size();++i) {
      |                  ~~^~~~~~~~~~~
hidden.cpp:94:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |   for (int i = 0;i <= O.size();++i) {
      |                  ~~^~~~~~~~~~~
hidden.cpp:97:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |    if (i < O.size())
      |        ~~^~~~~~~~~~
grader.cpp: In function 'int main()':
grader.cpp:28:26: warning: format '%d' expects argument of type 'int', but argument 3 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   28 |     fprintf (fifo_out, "%d\n", ans.size ());
      |                         ~^     ~~~~~~~~~~~
      |                          |              |
      |                          int            std::vector<int>::size_type {aka long unsigned int}
      |                         %ld
grader.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for (int i=0; i<ans.size () && i < N; i++)
      |                   ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...