제출 #288339

#제출 시각아이디문제언어결과실행 시간메모리
288339davi_bart커다란 상품 (IOI17_prize)C++17
컴파일 에러
0 ms0 KiB
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define ld long double
vector<int> ask(int i);
int find_best(int n){
  int l=0,r=n;
  while(l<r-1){
    int m=(l+r)/2;
    auto res=ask(m);
    if(res[0]==0)l=m;
    else r=m;
  }
  return l;
}
static const int max_q = 10000;
static int n;
static int query_count = 0;
static vector<int> g;
static vector<vector<int> > rank_count;

vector<int> ask(int i) {
	query_count++;
	if(query_count > max_q) {
		cerr << "Query limit exceeded" << endl;
		exit(0);
	}

	if(i < 0 || i >= n) {
		cerr << "Bad index: " << i << endl;
		exit(0);
	}

	vector<int> res(2);
	res[0] = rank_count[g[i] - 1][i + 1];
	res[1] = rank_count[g[i] - 1][n] - res[0];
	return res;
}

int main() {
	cin >> n;

	g.resize(n);
	for(int i = 0; i < n; i++) {
		cin >> g[i];
		if(g[i] < 1) {
			cerr << "Invalid rank " << g[i] << " at index " << i << endl;
			exit(0);
		}
	}

	int max_rank = *max_element(g.begin(), g.end());

	rank_count.resize(max_rank + 1, vector<int>(n + 1, 0));
	for(int r = 0; r <= max_rank; r++) {
		for(int i = 1; i <= n; i++) {
			rank_count[r][i] = rank_count[r][i - 1];
			if(g[i - 1] == r)
			  rank_count[r][i]++;
		}
	}

	for(int i = 0; i <= n; i++)
		for(int r = 1; r <= max_rank; r++)
			rank_count[r][i] += rank_count[r - 1][i];

	int res = find_best(n);
	cout << res << endl << "Query count: " << query_count << endl;

	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

/tmp/ccpkLGGO.o: In function `ask(int)':
grader.cpp:(.text+0x0): multiple definition of `ask(int)'
/tmp/ccscsCmE.o:prize.cpp:(.text+0x0): first defined here
/tmp/ccpkLGGO.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccscsCmE.o:prize.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status