結果

問題 No.9 モンスターのレベル上げ
ユーザー mbanmban
提出日時 2017-01-15 01:01:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,346 bytes
コンパイル時間 692 ms
コンパイル使用メモリ 74,768 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-23 10:51:14
合計ジャッジ時間 4,107 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 238 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<queue> 
#include<vector>

using namespace std;

int n;
int *a, *b;
int i,j,k;

void scan();
void solve();
int cnt(int index);
void write(int ans);

struct monstar
{
	int battle;
	int level;
};

struct temp :less<monstar>
{
	bool operator()(const monstar &a, const monstar &b) {
		if (a.level != b.level) {
			return a.level > b.level;
		}
		else
		{
			return a.battle < b.battle;
		}
	}
};

int main(void) {
	scan();
	solve();
	return 0;
}

void scan() {
	cin >> n;
	a = new int[n];
	b = new int[n];
	for (k = 0; k < n; k++) {
		cin >> a[i];
	}
	for (k = 0; k < n; k++) {
		cin >> b[i];
	}
}

void solve() {
	int ans = 9999999;
	for (j = 0; j < n; j++) {
		int a = cnt(j);
		if (a < ans) {
			ans = a;
		}
	}
	write(ans);
}

void write(int ans) {
	cout << ans << endl;
}

int cnt(int index) {
	priority_queue<monstar, vector<monstar>, temp> q;
	for (i = 0; i < n; i++) {
	    monstar add = { 0,a[i] };
		q.push(add);
	}
	for (i = index; i < n; i++) {
		monstar cp = q.top();
		cp.battle+=1;
		cp.level += b[i] / 2;
		q.pop();
		q.push(cp);
	}
	for (i = 0; i < index; i++) {
		monstar cp = q.top();
		q.pop();
		cp.battle+=1;
		cp.level += b[i] / 2;
		q.pop();
		q.push(cp);
	}
	int max = 0;
	for (i = 0; i < n; i++) {
		monstar m = q.top();
		if (max < m.battle) {
			max = m.battle;
		}
		q.pop();
	}
	return max;
}
0