結果

問題 No.484 収穫
ユーザー olpheolphe
提出日時 2017-02-10 23:44:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,641 bytes
コンパイル時間 775 ms
コンパイル使用メモリ 88,580 KB
実行使用メモリ 17,380 KB
最終ジャッジ日時 2023-08-28 10:18:35
合計ジャッジ時間 6,815 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "map"

using namespace std;
const long long int MOD = 1000000007;

typedef pair<int, int> P;
int N;
long long int num[2000];
long long int dis[2000];
bool flag[2000];
bool fflag[2001];
long long int ff;
long long int ans=LLONG_MAX;
long long int box;
long long int bag;
long long int current;
priority_queue<long long int, vector<long long int>, greater<long long int> >Q;
long long int node;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> num[i];
	}
	for (int i = 0; i < N; i++) {
		if (num[i] + N < ans) {
			for (int j = 0; j < N; j++) {
				dis[j] = LLONG_MAX;
				flag[j] = true;
				fflag[j] = true;
			}
			fflag[2000] = true;
			dis[i] = num[i];
			Q.push((dis[i] * 10000 + i) * 10000 + 2000);
			box = 0;
			while (!Q.empty() && box < N) {
				if (flag[(Q.top() % 100000000) / 10000] && fflag[(Q.top() % 10000)]) {
					current = Q.top();
					node = (current % 100000000) / 10000;
					dis[node] = current / 100000000;
					Q.pop();
					box++;
					flag[node] = false;
					fflag[current % 10000] = false;
					for (int j = 0; j < N; j++) {
						if (i != j) {
							if (max(dis[node] + abs(j - node), num[j]) < dis[j]) {
								Q.push(max(dis[node] + abs(j - node), num[j]) * 100000000 + j * 10000 + node);
							}
						}
					}
				}
				else {
					Q.pop();
				}
			}
			bag = 0;
			for (int j = 0; j < N; j++) {
				bag = max(bag, dis[j]);
			}
			ans = min(ans, bag);
		}
	}
	cout << ans << endl;
	return 0;
}
0