Submission #45212

#TimeUsernameProblemLanguageResultExecution timeMemory
45212realityHidden Sequence (info1cup18_hidden)C++17
100 / 100
6 ms640 KiB
#include "grader.h" #include "bits/stdc++.h" using namespace std; #define fi first #define se second #define ll long long #define dbg(v) cerr<<#v<<" = "<<v<<'\n' #define vi vector<int> #define vl vector <ll> #define pii pair<int,int> #define mp make_pair #define db long double #define pb push_back #define all(s) s.begin(),s.end() template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;} template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;} int get(string str) { vi cnt; for (auto it : str) cnt.pb(it - '0'); return isSubsequence(cnt); } vector < int > findSequence (int N) { const int lim = (N / 2) + 1; string str = ""; int w = 1; while (str.length() < lim && get(str + "0")) str += "0"; if (str.length() == lim) { w = 0; str = ""; while (get(str + "1")) str += "1"; } vector < string > S[2]; S[0].pb(""); S[1].pb(""); for (int i = 1;i <= N;++i) S[0].pb(S[0].back() + "0"),S[1].pb(S[1].back() + "1"); const int SZ = str.length(); string answer = ""; int l = 0,r = N - SZ; for (int i = 0;i <= SZ;++i) { int ok = 1; while (ok && r > 0) { if (SZ - i + l <= i + r) { if (get(S[w][l + 1] + S[w^1][SZ - i])) answer += w + '0',++l,--r; else ok = 0; } else { if (!get(S[w^1][i + 1] + S[w][r])) answer += w + '0',++l,--r; else ok = 0; } } if (i != SZ) answer += (1 - w) + '0'; } vi ans; for (auto it : answer) ans.pb(it - '0'); return ans; }

Compilation message (stderr)

hidden.cpp: In function 'std::vector<int> findSequence(int)':
hidden.cpp:29:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (str.length() < lim && get(str + "0")) str += "0";
            ~~~~~~~~~~~~~^~~~~
hidden.cpp:30:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (str.length() == lim) {
         ~~~~~~~~~~~~~^~~~~~
grader.cpp: In function 'int main()':
grader.cpp:28:43: warning: format '%d' expects argument of type 'int', but argument 3 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
     fprintf (fifo_out, "%d\n", ans.size ());
                                ~~~~~~~~~~~^
grader.cpp:29:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<ans.size () && i < N; i++)
                   ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...