답안 #315220

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
315220 2020-10-22T04:57:16 Z thtsshz_bgwrswh Mouse (info1cup19_mouse) C++17
컴파일 오류
0 ms 0 KB
#pragma GCC optimize("Ofast")
#include "grader.h"
#include<stdio.h>
#include<algorithm>
#include<assert.h>
using namespace std;
int num[500];
bool check[500],wrong[500];
void solve(int n){
	int i,j;
	for(i=0;i<n;i++)
		wrong[i]=check[i]=0;
	vector<int> vec(n);
	for(i=0;i<n;i++)
		vec[i]=i+1;
	random_shuffle(vec.begin(),vec.end());
	int now=query(vec);
	if(now==n)
		return;
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			swap(vec[j],vec[i]);
			int v=query(vec);
			if(v==n)
				return;
			if(v==now-2)
				check[i]=check[j]=1;
			else if(v==now)
				wrong[i]=wrong[j]=1;
			swap(vec[i],vec[j]);
		}
	} 
	vector<int> order;
	for(i=0;i<n;i++)
		if(wrong[i])
			order.emplace_back(i);
	for(i=0;i<n;i++)
		check[i]=0;
	for(i=0;i<(int)order.size();i++){
		for(j=i+1;j<(int)order.size();j++){
			if(check[i]||check[j])
				continue;
			swap(vec[order[i]],vec[order[j]]);
			int v=query(vec);
			if(v==n)
				return;
			if(v==now+2){
				now+=2;
				check[i]=check[j]=1;
				break;
			}
			swap(vec[order[i]],vec[order[index]]);
		}
	}
	while(1){
		for(i=0;i<(int)order.size();i++){
			for(j=i+1;j<(int)order.size();j++){
				if(check[i]||check[j])
					continue;
				swap(vec[order[i]],vec[order[j]]);
				int v=query(vec);
				if(v==n)
					return;
				if(v==now+2){
					now+=2;
					check[i]=check[j]=1;
					break;
				}
				else if(v==now+1)
					now++;	
				else
					swap(vec[order[i]],vec[order[j]]);
			}
		}
	}
}

Compilation message

mouse.cpp: In function 'void solve(int)':
mouse.cpp:52:32: error: no match for 'operator[]' (operand types are 'std::vector<int>' and '<unresolved overloaded function type>')
   52 |    swap(vec[order[i]],vec[order[index]]);
      |                                ^
In file included from /usr/include/c++/9/vector:67,
                 from /usr/include/c++/9/functional:62,
                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/9/algorithm:71,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from grader.h:5,
                 from mouse.cpp:2:
/usr/include/c++/9/bits/stl_vector.h:1040:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::reference = int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1040 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1040:28: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1040 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:1058:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) const [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::const_reference = const int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1058 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1058:28: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1058 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~