Submission #784204

# Submission time Handle Problem Language Result Execution time Memory
784204 2023-07-15T20:52:28 Z testanmdp Minerals (JOI19_minerals) C++14
Compilation error
0 ms 0 KB
///#include "minerals.h"
#include <bits/stdc++.h>
#include <cstdlib>
#include <algorithm>
#define DEBUG
void Solve(int N);
int Query(int x);

void Answer(int x, int y);
typedef std::pair<int,int> pii;
typedef std::pair<int,pii> pip;
int mid(pii k){
	return (k.first+k.second)/2;	
}
void Solve(int N) {
	
	std::vector<int> vec,bads;
	
  	for (int i = 1; i != 2*N+1; ++i) {
    	int x = Query(i);
    	//std::cout<<x<<"<\n";
    	if(x!=vec.size()){
    		vec.push_back(i);
		}else {
			bads.push_back(i);
			Query(i);
		}
  	}
  	
  	std::vector<pip> queries[N];
  	for(int i=0;i!=N;++i){
  		pip range = {bads[i],pii(0,N-1)};
  		queries[mid(range.second)].push_back(range);
	}
	bool match[N]={};
	bool skip[N]={};
  	int falta=N;
  	int last=N;
  	int min=mid({0,N-1}),max=mid({0,N-1});
  	while(falta){
  		int cur=N-1;
  		for(;cur>=0;--cur){
  			if(!falta)break;
  			for(auto&x:queries[cur]){
  				auto __ = x;
  				int p = Query(x.first);
  				///std::cout<<p<<" "<<i<<"\n";
  				if(p==last){///Estah contido
  					__.second.second=cur;
				}else {
					__.second.first=cur+1;
				}
				if(__.second.first!=__.second.second){
					queries[mid(__.second)].push_back(__);
					Query(x.first);
				}else {
					Answer(x.first,vec[__.second.first]);
					skip[__.second.first]=1;
					min=std::min(min,__.second.second);
					max=std::max(max,__.second.second);
					--falta;
					last=p;
				}
				
			}
			if(!skip[cur])
			last=Query(vec[cur]);
			//std::cout<<<<"!\n";
			queries[cur].clear();
		}
		for(;cur<=N-1;++cur){
			if(!falta)break;
			if(!skip[cur])
			last=Query(vec[cur]);
  			for(auto&x:queries[cur]){
  				auto __ = x;
  				int p = Query(x.first);
  			//	std::cout<<p<<" "<<i<<"\n";
  				if(p==last){///Estah contido
  					__.second.second=cur;
				}else {
					__.second.first=cur+1;
				}
				if(__.second.first!=__.second.second){
					queries[mid(__.second)].push_back(__);
					Query(x.first);
				}else {
					Answer(x.first,vec[__.second.first]);
					--falta;
					skip[__.second.first]=1;
					last=p;
					min=std::min(min,__.second.second);
					max=std::max(max,__.second.second);
				}
			}
			
			queries[cur].clear();
		}
	}
  	
}

#ifdef DEBUG
constexpr int MAX_N = 43000;
constexpr int MAX_CALLS = 1000000;

namespace {

void WrongAnswer(int code) {
  printf("Wrong Answer [%d]\n", code);
  exit(0);
}

int N;
int counterpart[2 * MAX_N + 1];

int num_queries;
int num_kinds;
int on[2 * MAX_N + 1];
int count[2 * MAX_N + 1];

int num_answers;
int answer[2 * MAX_N + 1];

}  // namespace

int Query(int x) {
  if (!(1 <= x && x <= 2 * N)) {
    WrongAnswer(1);
  }
  if (++num_queries > MAX_CALLS) {
    WrongAnswer(2);
  }
  const int type = std::min(x, counterpart[x]);
  if (on[x]) {
    --on[x];
    --count[type];
    if (count[type] == 0) {
      --num_kinds;
    }
  } else {
    ++on[x];
    ++count[type];
    if (count[type] == 1) {
      ++num_kinds;
    }
  }
  return num_kinds;
}

void Answer(int a, int b) {
//	std::cout<<"Match "<<a<<" "<<b<<"\n";
  if (++num_answers > N) {
    WrongAnswer(6);
  }
  if (!(1 <= a && a <= 2 * N && 1 <= b && b <= 2 * N)) {
    WrongAnswer(3);
  }
  if (answer[a] != 0) {
    WrongAnswer(4);
  }
  answer[a] = b;
  if (answer[b] != 0) {
    WrongAnswer(4);
  }
  answer[b] = a;
  if (!(counterpart[a] == b && counterpart[b] == a)) {
    WrongAnswer(5);
  }
}

int main() {
  if (scanf("%d", &N) != 1) {
    fprintf(stderr, "Error while reading input\n"); 
    exit(1);
  }
  std::vector<int> vec;
  for(int i=N+1;i!=2*N+1;++i)vec.push_back(i);
  std::random_shuffle(vec.begin(),vec.end());
  std::vector<int> vec2;
  for(int i=1;i!=N+1;++i)vec2.push_back(i);
  std::random_shuffle(vec2.begin(),vec2.end());
  for (int i = 1; i <= N; ++i) {
    int x=vec[i-1], y=vec2[i-1];
    //if (scanf("%d%d", &x, &y) != 2) {
      //fprintf(stderr, "Error while reading input\n");
      //exit(1);
    //}
   // std::cout<<"Create pair "<<x<<" "<<y<<"\n";
    counterpart[x] = y;
    counterpart[y] = x;
  }
  Solve(N);
  if (num_answers != N) {
    WrongAnswer(6);
  }
  printf("Accepted: %d\n", num_queries);
  return 0;
}
#endif

Compilation message

minerals.cpp: In function 'void Solve(int)':
minerals.cpp:22:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |      if(x!=vec.size()){
      |         ~^~~~~~~~~~~~
minerals.cpp:35:7: warning: unused variable 'match' [-Wunused-variable]
   35 |  bool match[N]={};
      |       ^~~~~
/usr/bin/ld: /tmp/cc0XYLoT.o: in function `Query(int)':
grader.cpp:(.text+0x30): multiple definition of `Query(int)'; /tmp/cchrwQsT.o:minerals.cpp:(.text+0x50): first defined here
/usr/bin/ld: /tmp/cc0XYLoT.o: in function `Answer(int, int)':
grader.cpp:(.text+0x100): multiple definition of `Answer(int, int)'; /tmp/cchrwQsT.o:minerals.cpp:(.text+0x120): first defined here
/usr/bin/ld: /tmp/cc0XYLoT.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cchrwQsT.o:minerals.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status