Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- //Do not change anything here. Go to line 42 to find the Participant class.
- int grader_N, grader_queries_used = 0;
- vector<int> grader_S;
- void grader_wa(string S) {
- cerr << S << '\n';
- cout << "fail" << '\n';
- exit(0);
- }
- int query(vector<int> X) {
- grader_queries_used++;
- if (grader_queries_used > 50)
- grader_wa("More than 50 queries used.");
- if ((int)X.size() != grader_N){
- grader_wa("Size of provided vector does not match for query");
- }
- for (int x : X){
- if (!(0 <= x && x <= 1)){
- grader_wa("Elements other than 0 or 1 found in vector for query");
- }
- }
- int intersection = 0;
- for (int i = 0; i < grader_N; i++){
- if (X[i] == 1 && grader_S[i] == 1){
- intersection++;
- }
- }
- intersection %= 2;
- return intersection;
- }
- struct Participant
- {
- //DO NOT CHANGE ANYTHING ABOVE THIS LINE!
- //You may create variables and functions here.
- int solve(int N)
- {
- // For demonstration purposes only
- // vector <int> A(N, 0);
- // A[0] = 1;
- // int queryResult = query(A);
- int a=0;
- int i=0;
- int mn = 0;
- mn = (1 << 14);
- vector<int> vec(N);
- while(true) {
- for(i=0;i<N;i++) {
- a = rand()%2;
- vec[i] = a;
- }
- a=0;
- a = query(vec);
- if(a)
- break;
- }
- vector<int> veco;
- while(true) {
- veco.clear();
- int b=0;
- for(i=0;i<N;i++) {
- if(vec[i] == 1)
- b++;
- }
- a=0;
- for(i=0;i<N;i++) {
- if(vec[i] == 0)
- veco.push_back(0);
- else if(a < (b/2)) {
- veco.push_back(1);
- a++;
- }
- else
- veco.push_back(0);
- }
- a = 0;
- a = query(veco);
- if(a) {
- vec = veco;
- }
- else {
- veco.clear();
- for(i=0;i < N;i++) {
- if(a >= (b/2))
- break;
- if(vec[i] == 1) {
- vec[i] = 0;
- a++;
- }
- }
- }
- a=0;
- for(i=0;i<N;i++) {
- if(vec[i] == 1)
- a++;
- }
- if(a == 1)
- break;
- }
- for(i=0;i < N;i++) {
- if(vec[i] == 1)
- return i;
- }
- // return 0;
- }
- //DO NOT CHANGE ANYTHING BELOW THIS LINE!
- };
- int main() {
- cin >> grader_N;
- grader_S = vector<int>(grader_N);
- for(int i = 0; i < grader_N; i++){
- int x; cin >> x;
- grader_S[i] = x;
- }
- grader_queries_used = 0;
- Participant pa;
- int result = pa.solve(grader_N);
- cerr << "Returned value = " << result << "\n";
- if (!(0 <= result && result < grader_N)){
- grader_wa("Returned value out of bounds");
- }
- if (grader_S[result] == 0){
- grader_wa("Returned value not in set");
- }
- cout << "pass\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement