Skip to content

Commit 7ab3fd8

Browse files
info1cup 18-hidden
1 parent 54c0098 commit 7ab3fd8

File tree

3 files changed

+140
-0
lines changed

3 files changed

+140
-0
lines changed
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include<bits/stdc++.h>
2+
#include "grader.h"
3+
4+
using namespace std;
5+
6+
static int maxQ = 0;
7+
static vector < int > theRealAnswer;
8+
9+
bool isSubsequence (vector < int > v)
10+
{
11+
if (v.size () > maxQ)
12+
maxQ = v.size ();
13+
int i = 0;
14+
for (auto it : v)
15+
{
16+
while (i < theRealAnswer.size () && it != theRealAnswer[i]) i ++;
17+
if (i == theRealAnswer.size ()) return 0;
18+
i ++;
19+
}
20+
return 1;
21+
}
22+
23+
int main ()
24+
{
25+
int n, x;
26+
scanf ("%d", &n), maxQ = 0;
27+
for (int i=1; i<=n; i++)
28+
scanf ("%d", &x), theRealAnswer.push_back (x);
29+
30+
vector < int > ans = findSequence (n);
31+
if (ans.size () != theRealAnswer.size ())
32+
{
33+
printf ("Different lengths\n");
34+
for (auto it : ans)
35+
printf ("%d ", it);
36+
printf ("\n");
37+
return 0;
38+
}
39+
40+
for (int i=0; i<ans.size (); i++)
41+
if (ans[i] != theRealAnswer[i])
42+
{
43+
printf ("WA position %d\n", i + 1);
44+
for (auto it : ans)
45+
printf ("%d ", it);
46+
printf ("\n");
47+
return 0;
48+
}
49+
printf ("Ok, biggest queried length %d\n", maxQ);
50+
return 0;
51+
}
52+

Info1Cup/Info1Cup 18-Hidden/grader.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include<bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
bool isSubsequence (vector < int > v);
6+
vector < int > findSequence (int N);
7+
+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* See: https://github.com/stefdasca/CompetitiveProgramming/blob/master/Info1Cup/2018%20-%20International%20Round/Info1Cup%2018-Hidden.cpp
3+
* And: https://github.com/tmwilliamlin168/CompetitiveProgramming/blob/master/Info1Cup/18-Hidden.cpp
4+
*/
5+
6+
#include <bits/stdc++.h>
7+
#include "grader.h"
8+
9+
using namespace std;
10+
11+
bool qry(int zeroes, int ones, bool rev = false) {
12+
vector<int> v;
13+
for (int i = 0; i < zeroes; i++) {
14+
v.push_back(0);
15+
}
16+
for (int j = 0; j < ones; j++) {
17+
v.push_back(1);
18+
}
19+
if (rev) reverse(v.begin(), v.end());
20+
return isSubsequence(v);
21+
}
22+
23+
vector<int> findSequence (int N)
24+
{
25+
int numZeroes = 1, numOnes = 1;
26+
for (; numZeroes <= N/2+1; numZeroes++) {
27+
if (qry(numZeroes, 0)) {
28+
continue;
29+
} else {
30+
break;
31+
}
32+
}
33+
numZeroes--;
34+
if (numZeroes == N/2+1) {
35+
for (; numOnes <= N/2+1; numOnes++) {
36+
if (qry(0, numOnes, true)) {
37+
continue;
38+
} else {
39+
break;
40+
}
41+
}
42+
numOnes--;
43+
numZeroes = N - numOnes;
44+
} else {
45+
numOnes = N - numZeroes;
46+
}
47+
48+
vector<int> ans;
49+
int usedZeroes = 0;
50+
51+
for (int i = 0; i < numOnes; i++) {
52+
int newZeroes = 0;
53+
for (int j = 1; j <= numZeroes - usedZeroes; j++) {
54+
if (usedZeroes + j + numOnes - i <= N/2+1) {
55+
if (qry(usedZeroes + j, numOnes - i)) {
56+
newZeroes++;
57+
} else {
58+
break;
59+
}
60+
} else {
61+
if (qry(numZeroes - usedZeroes - j, i+1, true) && !qry(numZeroes - usedZeroes - (j-1), i+1, true)) {
62+
newZeroes = j;
63+
} else {
64+
continue;
65+
}
66+
}
67+
}
68+
for (int i = 0; i < newZeroes; i++) {
69+
ans.push_back(0);
70+
}
71+
ans.push_back(1);
72+
usedZeroes += newZeroes;
73+
}
74+
75+
while ((int)ans.size() != N) {
76+
ans.push_back(0);
77+
}
78+
79+
return ans;
80+
}
81+

0 commit comments

Comments
 (0)