結果

問題 No.2248 max(C)-min(C)
コンテスト
ユーザー Shawn stayC
提出日時 2023-04-20 23:31:41
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 693 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,482 ms
コンパイル使用メモリ 215,244 KB
実行使用メモリ 14,388 KB
最終ジャッジ日時 2026-06-30 09:21:58
合計ジャッジ時間 6,397 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 WA * 45
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(int i=(l);i<(r);++i)

int main(){
	ll n; cin>>n;
	vector<vector<ll>> g(3,vector<ll> (n));
	rep(i,0,n) cin>>g[0][i];
	rep(i,0,n) cin>>g[1][i];
	rep(i,0,n) g[2][i]=(g[0][i]+g[1][i])/2;
	vector<vector<ll>> dp(3,vector<ll> (n));
	dp[0][0]=g[0][0]; dp[1][0]=g[1][0]; dp[2][0]=g[2][0];
	rep(i,1,n){
		rep(j,0,3){
			ll mn=1e9, id=0;
			rep(k,0,3){
				if(mn>abs(dp[j][i-1]-g[k][i])) {mn=abs(dp[j][i-1]-g[k][i]), id=k;}
			}
			dp[j][i]=g[id][i];
		}
	}
	ll ans=1e9;
	rep(i,0,3){
		ll mx=0, mn=1e9;
		rep(j,0,n){
			mx=max(mx,dp[i][j]);
			mn=min(mn,dp[i][j]);
		}
		ans=min(ans,mx-mn);
	}
	cout<<ans<<endl;
}
0