結果

問題 No.1767 BLUE to RED
ユーザー kotatsugame
提出日時 2021-11-26 22:40:30
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 542 bytes
コンパイル時間 546 ms
コンパイル使用メモリ 67,456 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-29 18:16:39
合計ジャッジ時間 3,855 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:5:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    5 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
int N,M,A[2<<17],B[2<<17];
main()
{
	cin>>N>>M;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<M;i++)cin>>B[i];
	int id=0;
	int ans=0;
	for(int i=0;i<M;)
	{
		while(id<N&&A[id]<B[i])id++;
		int L=id>0?A[id-1]:-1e9;
		int R=id<N?A[id]:2e9;
		int j=i;
		while(j<M&&B[j]<R)j++;
		if(i+1==j)
		{
			ans+=min(R-B[i],B[i]-L);
		}
		else
		{
			int now=min(R-B[i],B[j-1]-L);
			for(int k=i;k+1<j;k++)
			{
				now=min(now,R-B[k+1]+B[k]-L);
			}
			ans+=now;
		}
		i=j;
	}
	cout<<ans<<endl;
}
0