結果

問題 No.9 モンスターのレベル上げ
ユーザー FF256grhyFF256grhy
提出日時 2015-05-12 08:45:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,262 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 26,580 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 03:39:29
合計ジャッジ時間 5,096 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>

void make_table();
void add(int, int);

int n, a[1500], b[1500], table[15001], buttle[1501], next[1501];

int main(void) {
	scanf("%d", &n);
	int i, j;
 	for(i = 0; i < n; i++) { scanf("%d", &a[i]); }
	for(i = 0; i < n; i++) { scanf("%d", &b[i]); b[i] /= 2; }
	
	int min = 1501;
	for(i = 0; i < n; i++) { // i: 開始位置
		int max = 0;
		make_table();
		int min_p = 0;
		for(j = 0; j < n; j++) {
			int k = (i + j) % n;
			
			int l = min_p;
			while(table[l] == 0) { l++; }
			min_p = l;
			
			int p = table[l];
			table[l] = next[p];
			
			buttle[p]++;
			max = max < buttle[p] ? buttle[p] : max;
			add(l + b[k], p);
		}
		min = max < min ? max : min;
	}
	
	printf("%d\n", min);
	return 0;
}

void make_table() {
	int i;
	for(i = 0; i < 15001; i++) { table[i] = 0; }
	for(i = 0; i < 1501;  i++) { buttle[i] = 0; next[i] = 0; }
	
	for(i = 0; i < n; i++) {
		next[i + 1] = table[ a[i] ]; // 先頭につないでいく
		table[ a[i] ] = i + 1;
	}
	buttle[0] = 1501; // 番兵
	return;
}

void add(int l, int p) {
	if(buttle[p] <= buttle[ table[l] ]) {
		next[p] = next[ table[l] ];
		table[l] = p;
	} else {
		int q = table[l];
		while( buttle[ next[q] ] < buttle[p] ) { q = next[q]; }
		next[p] = next[q];
		next[q] = p;
	}
	return;
}
0