답안 #72220

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
72220 2018-08-26T06:06:50 Z BOJ 8481(#2179, veydpz, jh05013, 16silver) 흔한 자료구조 문제 (FXCUP3_easy) C++17
0 / 100
1000 ms 764 KB
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int n,q;
int arr[110];
int pos[110];
int x[400];
int base;
bool same(vector<int> a, vector<int> b){
	if(a.size() != b.size()) return false;
	for(int i=0; i<a.size(); i++){
		if(a[i] != b[i]) return false;
	}
	return true;
}
vector<int> get_list(int s, int e){
	vector<int> ret;
	s += (base-1);
	e += (base-1);
	if(s == e){
		ret.push_back(x[s]);
	}
	while(s < e){
		if(s % 2 == 1){
			ret.push_back(x[s]);
			s += 1;
		}
		if(e % 2 == 0){
			ret.push_back(x[e]);
			e -= 1;
		}
		s /= 2;
		e /= 2;
		if(s == e){
			ret.push_back(x[s]);
		}
	}
	sort(ret.begin(), ret.end());
	return ret;
}
void answer_query(vector<int> query){
	int minx;
	int maxx = -1;
	minx = n+10;
	for(int i=0; i<query.size(); i++){
		minx = min(minx, pos[query[i]]);
		maxx = max(maxx, pos[query[i]]);
	}
	for(int s=minx; s>=1; s--){
		for(int e=maxx; e<=n; e++){
			if(same(get_list(s, e), query)){
				printf("%d %d\n", s, e);
				return;
			}
		}
	}
	printf("-1\n");
}
int main(){
	scanf("%d%d", &n, &q);
	for(int i=1; i<=n; i++){
		scanf("%d", &arr[i]);
		pos[arr[i]] = i;
	}
	base = 1;
	while(base < n) base *= 2;
	for(int i=1; i<=n; i++){
		x[base+i-1] = arr[i];
	}
	for(int i=base-1; i>=1; i--){
		x[i] = min(x[2*i], x[2*i+1]);
	}
	while(q--){
		vector<int> query;
		int c;
		scanf("%d", &c);
		for(int i=1; i<=c; i++){
			int temp;
			scanf("%d", &temp);
			query.push_back(temp);
		}
		answer_query(query);
	}
}

Compilation message

easy.cpp: In function 'bool same(std::vector<int>, std::vector<int>)':
easy.cpp:12:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<a.size(); i++){
               ~^~~~~~~~~
easy.cpp: In function 'void answer_query(std::vector<int>)':
easy.cpp:46:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<query.size(); i++){
               ~^~~~~~~~~~~~~
easy.cpp: In function 'int main()':
easy.cpp:61:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &q);
  ~~~~~^~~~~~~~~~~~~~~~
easy.cpp:63:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &arr[i]);
   ~~~~~^~~~~~~~~~~~~~~
easy.cpp:77:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &c);
   ~~~~~^~~~~~~~~~
easy.cpp:80:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &temp);
    ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Correct
2 Correct 3 ms 400 KB Correct
3 Correct 3 ms 604 KB Correct
4 Correct 333 ms 604 KB Correct
5 Correct 19 ms 604 KB Correct
6 Correct 155 ms 712 KB Correct
7 Execution timed out 1060 ms 764 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Correct
2 Correct 3 ms 400 KB Correct
3 Correct 3 ms 604 KB Correct
4 Correct 333 ms 604 KB Correct
5 Correct 19 ms 604 KB Correct
6 Correct 155 ms 712 KB Correct
7 Execution timed out 1060 ms 764 KB Time limit exceeded
8 Halted 0 ms 0 KB -