답안 #260139

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
260139 2020-08-09T11:30:13 Z user202729 코알라 (APIO17_koala) C++17
컴파일 오류
0 ms 0 KB
// moreflags=grader.cpp
// 6
#include "koala.h"
#if not LOCAL
#define NDEBUG
#endif
#include<vector>
#include<cassert>
#include<algorithm>

#if LOCAL
#include<cstdio>
#endif

std::vector<int>& play(std::vector<int>& data, std::vector<int>& result){
	assert(result.size()==data.size());
	playRound(data.data(), result.data());
	return result;
}
std::vector<int> play(std::vector<int>& data){
	std::vector<int> result(data.size());
	play(data, result);
	return result;
}

int minValue(int N, int W) {
	assert(N==W);
	std::vector<int> data(N);
	data[0]=1;
	auto result=play(data);
	for(int i=0; i<N; ++i)
		if(result[i]<=data[i])
			return i;
}

int maxValue(int N, int W) {
	std::vector<int> data(N, 1);
	std::vector<int> result(N);
	while(true){
		auto c=(int)std::count_if(begin(data), end(data),[&](int it){return it>0;});
		if(c==1)
			return int(std::find_if(begin(data), end(data),[&](int it){return it>0;})-data.begin());
		int value=W/c;
		while([&]{
			int tmp=0;
			for(int i=N-c; i>N-c-value; --i) tmp+=i;
			return tmp;
		}()>=N) {
			--value;
			assert(value>=1);
		}

		for(auto& it: data)
			if(it>0) it=W/c;

		play(data, result);
		for(int i=0; i<N; ++i)
			if(result[i]<=data[i])
				data[i]=0;
	}
}

int greaterValue(int N, int W) {
	std::vector<int> data(N), result(N);

	auto const check=[&](int value){
		assert(value>0);
		value+=value>=6;
		data[0]=data[1]=value;
		play(data, result);
		if(result[0]>data[0] and result[1]>data[1]){
			return 2;
		}else if(result[0]<=data[0] and result[1]<=data[1]){
			return 0;
		}else{
			return 1;
		}
	};

	if(0){
		for(int i=1; i<12; ++i)
			std::fprintf(stderr, "%d", check(i));
		std::fprintf(stderr, "\n");
		return 0;
	}

	int k=0;
	for(auto step=1<<3;;){
		step>>=1;
		assert(step!=0);
		switch(check(k+step)){
			case 2: k+=step; break;
			case 0: break;
			case 1:
				if(result[0]>data[0]) return 0; else return 1;
		}
	}
}

void allValues(int N, int W, int *P) {
    if (W == 2*N) {
        // TODO: Implement Subtask 4 solution here.
        // You may leave this block unmodified if you are not attempting this
        // subtask.
    } else {
        // TODO: Implement Subtask 5 solution here.
        // You may leave this block unmodified if you are not attempting this
        // subtask.
    }
}

Compilation message

koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:82:9: error: 'fprintf' is not a member of 'std'
    std::fprintf(stderr, "%d", check(i));
         ^~~~~~~
koala.cpp:82:17: error: 'stderr' was not declared in this scope
    std::fprintf(stderr, "%d", check(i));
                 ^~~~~~
koala.cpp:83:8: error: 'fprintf' is not a member of 'std'
   std::fprintf(stderr, "\n");
        ^~~~~~~
koala.cpp:83:16: error: 'stderr' was not declared in this scope
   std::fprintf(stderr, "\n");
                ^~~~~~
koala.cpp: In function 'int minValue(int, int)':
koala.cpp:34:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^