답안 #786873

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
786873 2023-07-18T14:06:07 Z Deepesson Minerals (JOI19_minerals) C++17
80 / 100
38 ms 13792 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;
    int oopsie[N]={};

  	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 {
		    oopsie[bads.size()]=vec.size()-1;
			bads.push_back(i);
		}
  	}

  	std::vector<pip> queries[N];
  	bool skip[N]={};
  	for(int i=0;i!=N;++i){
  		pip range = {bads[i],pii(0,N-1)};
  		queries[mid(range.second)].push_back(range);
	}

  	int falta=N;
  	int last=N;
  	int curl=0,curr=N-1;
  	int times=0,c2=0;
  	while(falta){

  		for(int i=N-1;i!=-1;--i){
  			if(!falta)break;
  			for(auto&x:queries[i]){
                x.second.first=std::max(x.second.first,curl);
                x.second.second=std::min(x.second.second,curr);
  				auto __ = x;
  				int p = -1;
  				if(!skip[i]){
  				p = Query(x.first);++c2;}
  				///std::cout<<p<<" "<<i<<"\n";
  				if(p==last){///Estah contido
  					__.second.second=i;
				}else {
					__.second.first=i+1;
				}
				if(__.second.first!=__.second.second){
					queries[mid(__.second)].push_back(__);
					//last=Query(x.first);
					last=p;
				}else {
					Answer(x.first,vec[__.second.first]);
					skip[__.second.first]=1;
					--falta;
					last=p;
				}
				while(curr>0&&skip[curr])--curr;
				while(curl<0&&skip[curl])++curl;
			}
			if(!skip[i]){
			last=Query(vec[i]);++times;}
			//std::cout<<<<"!\n";
			queries[i].clear();
		}
		for(int i=0;i!=N;++i){
			if(!falta)break;
			if(!skip[i]){
			last=Query(vec[i]);++times;}
  			for(auto&x:queries[i]){
                x.second.first=std::max(x.second.first,curl);
                x.second.second=std::min(x.second.second,curr);
  				auto __ = x;
  				int p = -1;
  				if(!skip[i]){
  				p = Query(x.first);++c2;}
  			//	std::cout<<p<<" "<<i<<"\n";
  				if(p==last){///Estah contido
  					__.second.second=i;
				}else {
					__.second.first=i+1;
				}
				if(__.second.first!=__.second.second){
					queries[mid(__.second)].push_back(__);
					//last=Query(x.first);
					last=p;
				}else {
					Answer(x.first,vec[__.second.first]);
					skip[__.second.first]=1;
					--falta;
					last=p;
				}
				while(curr>0&&skip[curr])--curr;
				while(curl<0&&skip[curl])++curl;
			}
			queries[i].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:23:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |      if(x!=vec.size()){
      |         ~^~~~~~~~~~~~
minerals.cpp:70:28: warning: array subscript -1 is below array bounds of 'bool [(<anonymous> + 1)]' [-Warray-bounds]
   70 |     while(curl<0&&skip[curl])++curl;
      |                   ~~~~~~~~~^
minerals.cpp:105:28: warning: array subscript -1 is below array bounds of 'bool [(<anonymous> + 1)]' [-Warray-bounds]
  105 |     while(curl<0&&skip[curl])++curl;
      |                   ~~~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 KB Output is correct
2 Correct 1 ms 720 KB Output is correct
3 Correct 4 ms 1104 KB Output is correct
4 Correct 6 ms 2128 KB Output is correct
5 Correct 13 ms 4104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 720 KB Output is correct
7 Correct 4 ms 1104 KB Output is correct
8 Correct 6 ms 2128 KB Output is correct
9 Correct 13 ms 4104 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 7 ms 3392 KB Output is correct
12 Correct 10 ms 4028 KB Output is correct
13 Correct 9 ms 4052 KB Output is correct
14 Correct 10 ms 4020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 720 KB Output is correct
7 Correct 4 ms 1104 KB Output is correct
8 Correct 6 ms 2128 KB Output is correct
9 Correct 13 ms 4104 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 7 ms 3392 KB Output is correct
12 Correct 10 ms 4028 KB Output is correct
13 Correct 9 ms 4052 KB Output is correct
14 Correct 10 ms 4020 KB Output is correct
15 Correct 34 ms 13216 KB Output is correct
16 Correct 38 ms 13216 KB Output is correct
17 Correct 24 ms 13156 KB Output is correct
18 Correct 24 ms 12820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 720 KB Output is correct
7 Correct 4 ms 1104 KB Output is correct
8 Correct 6 ms 2128 KB Output is correct
9 Correct 13 ms 4104 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 7 ms 3392 KB Output is correct
12 Correct 10 ms 4028 KB Output is correct
13 Correct 9 ms 4052 KB Output is correct
14 Correct 10 ms 4020 KB Output is correct
15 Correct 34 ms 13216 KB Output is correct
16 Correct 38 ms 13216 KB Output is correct
17 Correct 24 ms 13156 KB Output is correct
18 Correct 24 ms 12820 KB Output is correct
19 Correct 33 ms 13444 KB Output is correct
20 Correct 38 ms 13520 KB Output is correct
21 Correct 34 ms 13296 KB Output is correct
22 Correct 32 ms 13128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 720 KB Output is correct
7 Correct 4 ms 1104 KB Output is correct
8 Correct 6 ms 2128 KB Output is correct
9 Correct 13 ms 4104 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 7 ms 3392 KB Output is correct
12 Correct 10 ms 4028 KB Output is correct
13 Correct 9 ms 4052 KB Output is correct
14 Correct 10 ms 4020 KB Output is correct
15 Correct 34 ms 13216 KB Output is correct
16 Correct 38 ms 13216 KB Output is correct
17 Correct 24 ms 13156 KB Output is correct
18 Correct 24 ms 12820 KB Output is correct
19 Correct 33 ms 13444 KB Output is correct
20 Correct 38 ms 13520 KB Output is correct
21 Correct 34 ms 13296 KB Output is correct
22 Correct 32 ms 13128 KB Output is correct
23 Correct 31 ms 13684 KB Output is correct
24 Correct 30 ms 13684 KB Output is correct
25 Correct 36 ms 13508 KB Output is correct
26 Correct 36 ms 13344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 720 KB Output is correct
7 Correct 4 ms 1104 KB Output is correct
8 Correct 6 ms 2128 KB Output is correct
9 Correct 13 ms 4104 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 7 ms 3392 KB Output is correct
12 Correct 10 ms 4028 KB Output is correct
13 Correct 9 ms 4052 KB Output is correct
14 Correct 10 ms 4020 KB Output is correct
15 Correct 34 ms 13216 KB Output is correct
16 Correct 38 ms 13216 KB Output is correct
17 Correct 24 ms 13156 KB Output is correct
18 Correct 24 ms 12820 KB Output is correct
19 Correct 33 ms 13444 KB Output is correct
20 Correct 38 ms 13520 KB Output is correct
21 Correct 34 ms 13296 KB Output is correct
22 Correct 32 ms 13128 KB Output is correct
23 Correct 31 ms 13684 KB Output is correct
24 Correct 30 ms 13684 KB Output is correct
25 Correct 36 ms 13508 KB Output is correct
26 Correct 36 ms 13344 KB Output is correct
27 Incorrect 33 ms 13792 KB Wrong Answer [2]
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 720 KB Output is correct
7 Correct 4 ms 1104 KB Output is correct
8 Correct 6 ms 2128 KB Output is correct
9 Correct 13 ms 4104 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 7 ms 3392 KB Output is correct
12 Correct 10 ms 4028 KB Output is correct
13 Correct 9 ms 4052 KB Output is correct
14 Correct 10 ms 4020 KB Output is correct
15 Correct 34 ms 13216 KB Output is correct
16 Correct 38 ms 13216 KB Output is correct
17 Correct 24 ms 13156 KB Output is correct
18 Correct 24 ms 12820 KB Output is correct
19 Correct 33 ms 13444 KB Output is correct
20 Correct 38 ms 13520 KB Output is correct
21 Correct 34 ms 13296 KB Output is correct
22 Correct 32 ms 13128 KB Output is correct
23 Correct 31 ms 13684 KB Output is correct
24 Correct 30 ms 13684 KB Output is correct
25 Correct 36 ms 13508 KB Output is correct
26 Correct 36 ms 13344 KB Output is correct
27 Incorrect 33 ms 13792 KB Wrong Answer [2]
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 720 KB Output is correct
7 Correct 4 ms 1104 KB Output is correct
8 Correct 6 ms 2128 KB Output is correct
9 Correct 13 ms 4104 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 7 ms 3392 KB Output is correct
12 Correct 10 ms 4028 KB Output is correct
13 Correct 9 ms 4052 KB Output is correct
14 Correct 10 ms 4020 KB Output is correct
15 Correct 34 ms 13216 KB Output is correct
16 Correct 38 ms 13216 KB Output is correct
17 Correct 24 ms 13156 KB Output is correct
18 Correct 24 ms 12820 KB Output is correct
19 Correct 33 ms 13444 KB Output is correct
20 Correct 38 ms 13520 KB Output is correct
21 Correct 34 ms 13296 KB Output is correct
22 Correct 32 ms 13128 KB Output is correct
23 Correct 31 ms 13684 KB Output is correct
24 Correct 30 ms 13684 KB Output is correct
25 Correct 36 ms 13508 KB Output is correct
26 Correct 36 ms 13344 KB Output is correct
27 Incorrect 33 ms 13792 KB Wrong Answer [2]
28 Halted 0 ms 0 KB -