Submission #362010

#TimeUsernameProblemLanguageResultExecution timeMemory
362010ogibogi2004Hidden Sequence (info1cup18_hidden)C++14
100 / 100
8 ms492 KiB
#include<bits/stdc++.h> #include "grader.h" using namespace std; vector < int > findSequence (int N) { vector < int > ans; int cnt0,cnt1=-1,n=N,halfn=n/2+1; vector<int>ivan; for(int i=1;i<=halfn;i++) { ivan.clear(); for(int j=0;j<i;j++) { ivan.push_back(1); } if(!isSubsequence(ivan)) { cnt1=i-1; cnt0=n-cnt1; break; } } if(cnt1==-1) { for(int i=1;i<=halfn;i++) { ivan.clear(); for(int j=0;j<i;j++) { ivan.push_back(0); } if(!isSubsequence(ivan)) { cnt0=i-1; cnt1=n-cnt0; break; } } } while(ans.size()<n) { if(cnt0==0) { ans.push_back(1); cnt1--; continue; } if(cnt1==0) { ans.push_back(0); cnt0--; continue; } vector<int>ivan1,ivan2; for(int i=0;i<ans.size();i++) { if(ans[i]==0)ivan1.push_back(0); else ivan2.push_back(1); } ivan1.push_back(0); ivan2.push_back(1); for(int i=0;i<cnt1;i++)ivan1.push_back(1); for(int i=0;i<cnt0;i++)ivan2.push_back(0); if(ivan1.size()<ivan2.size()) { if(isSubsequence(ivan1)) { ans.push_back(0); cnt0--; } else { ans.push_back(1); cnt1--; } } else { if(isSubsequence(ivan2)) { ans.push_back(1); cnt1--; } else { ans.push_back(0); cnt0--; } } } return ans; }

Compilation message (stderr)

hidden.cpp: In function 'std::vector<int> findSequence(int)':
hidden.cpp:42:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |  while(ans.size()<n)
      |        ~~~~~~~~~~^~
hidden.cpp:57:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   for(int i=0;i<ans.size();i++)
      |               ~^~~~~~~~~~~
hidden.cpp:44:3: warning: 'cnt0' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |   if(cnt0==0)
      |   ^~
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...