結果

問題 No.1104 オンライン点呼
ユーザー leaf_1415leaf_1415
提出日時 2020-07-03 21:59:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,721 bytes
コンパイル時間 2,216 ms
コンパイル使用メモリ 89,164 KB
実行使用メモリ 14,384 KB
最終ジャッジ日時 2023-10-17 02:12:46
合計ジャッジ時間 3,715 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,632 KB
testcase_01 AC 38 ms
12,988 KB
testcase_02 AC 36 ms
12,988 KB
testcase_03 AC 32 ms
12,988 KB
testcase_04 AC 3 ms
7,628 KB
testcase_05 AC 2 ms
7,628 KB
testcase_06 AC 3 ms
7,628 KB
testcase_07 AC 21 ms
10,796 KB
testcase_08 AC 9 ms
8,864 KB
testcase_09 AC 46 ms
14,384 KB
testcase_10 AC 3 ms
7,628 KB
testcase_11 AC 15 ms
9,832 KB
testcase_12 AC 21 ms
10,888 KB
testcase_13 AC 15 ms
9,564 KB
testcase_14 AC 4 ms
7,772 KB
testcase_15 AC 26 ms
11,140 KB
testcase_16 WA -
testcase_17 AC 20 ms
10,312 KB
testcase_18 AC 25 ms
11,144 KB
testcase_19 AC 32 ms
12,076 KB
testcase_20 AC 34 ms
12,428 KB
testcase_21 AC 34 ms
12,468 KB
testcase_22 AC 28 ms
11,620 KB
testcase_23 AC 24 ms
10,748 KB
testcase_24 AC 11 ms
8,956 KB
testcase_25 AC 2 ms
7,632 KB
testcase_26 AC 3 ms
7,632 KB
testcase_27 AC 3 ms
7,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

struct edge{
	llint to, cost;
	edge(){}
	edge(llint a, llint b){
		to = a, cost = b;
	}
};

llint n, k;
llint a[100005], b[100005];
vector<edge> G[100005];
llint dist[100005];

void dijkstra(vector<edge> G[], llint S, llint dist[])
{
	for(int i = 1; i <= n; i++) dist[i] = inf;
	dist[S] = 0;
	
	priority_queue< P, vector<P>, greater<P> > Q;
	Q.push( make_pair(0, S) );
	
	llint v, d;
	while(Q.size()){
		d = Q.top().first;
		v = Q.top().second;
		Q.pop();
		if(dist[v] < d) continue;
		for(int i = 0; i < G[v].size(); i++){
			if(dist[G[v][i].to] > d + G[v][i].cost){
				dist[G[v][i].to] = d + G[v][i].cost;
				Q.push( make_pair(dist[G[v][i].to], G[v][i].to) );
			}
		}
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) cin >> b[i];
	
	for(int i = 2; i <= n; i++){
		if(i-2 >= 1) G[i-2].push_back(edge(i, a[i-2]+b[i]+k));
		G[i-1].push_back(edge(i, a[i-1]+b[i]));
	}
	dijkstra(G, 1, dist);
	
	llint ans = 0;
	for(int i = 1; i <= n; i++) ans = max(ans, dist[i]);
	cout << ans << endl;
	
	return 0;
}
0