結果
| 問題 | No.9 モンスターのレベル上げ |
| コンテスト | |
| ユーザー |
FF256grhy
|
| 提出日時 | 2015-05-12 10:32:26 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3,258 ms / 5,000 ms |
| コード長 | 1,432 bytes |
| コンパイル時間 | 158 ms |
| コンパイル使用メモリ | 23,492 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-23 22:37:19 |
| 合計ジャッジ時間 | 4,668 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:14:39: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | for(i = 0; i < n; i++) { scanf("%d", &a[i]); }
| ~~~~~^~~~~~~~~~~~~
main.cpp:15:39: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | for(i = 0; i < n; i++) { scanf("%d", &b[i]); b[i] /= 2; }
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#define N_MAX 1500
#define L_MAX 15000
void make_table();
void add(int, int);
int n, a[N_MAX], b[N_MAX], table[L_MAX + 1], buttle[N_MAX + 1], next[N_MAX + 1];
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 = N_MAX + 1;
for(i = 0; i < n; i++) { // i: 開始位置
make_table();
int max = 0, l = 0;
for(j = 0; j < n; j++) { // (i + j) % n と戦う
while(table[l] == 0) { l++; }
int p = table[l];
buttle[p]++;
max = max < buttle[p] ? buttle[p] : max;
table[l] = next[p];
add(l + b[ (i + j) % n ], p);
}
min = max < min ? max : min;
}
printf("%d\n", min);
return 0;
}
void make_table() {
int i;
for(i = 0; i <= L_MAX; i++) { table[i] = 0; }
for(i = 0; i <= N_MAX; i++) { buttle[i] = 0; next[i] = 0; }
for(i = 0; i < n; i++) {
// buttleはどうせ0なので放置
next[i + 1] = table[ a[i] ]; // 先頭に挿入していく
table[ a[i] ] = i + 1; // 0はnullなので+1
}
buttle[0] = N_MAX + 1; // 番兵
return;
}
void add(int l, int p) {
if(buttle[p] <= buttle[ table[l] ]) { // 先頭に挿入する場合
next[p] = 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;
}
FF256grhy