結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void make_table()’:
main.cpp:42:40: warning: iteration 15001 invokes undefined behavior [-Waggressive-loop-optimizations]
  for(i = 0; i < 20001; i++) { table[i] = 0; }
                               ~~~~~~~~~^~~
main.cpp:42:15: note: within this loop
  for(i = 0; i < 20001; i++) { table[i] = 0; }
             ~~^~~~~~~

ソースコード

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 < 20001; i++) { table[i] = 0; }
	for(i = 0; i < 1500; 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