結果

問題 No.1767 BLUE to RED
ユーザー kotatsugamekotatsugame
提出日時 2021-11-26 22:40:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 542 bytes
コンパイル時間 679 ms
コンパイル使用メモリ 67,176 KB
実行使用メモリ 5,044 KB
最終ジャッジ日時 2023-09-12 05:16:24
合計ジャッジ時間 4,383 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 84 ms
4,380 KB
testcase_10 AC 109 ms
4,620 KB
testcase_11 AC 92 ms
4,444 KB
testcase_12 AC 84 ms
4,380 KB
testcase_13 AC 120 ms
4,736 KB
testcase_14 AC 149 ms
4,864 KB
testcase_15 AC 148 ms
4,976 KB
testcase_16 AC 149 ms
4,908 KB
testcase_17 AC 149 ms
5,028 KB
testcase_18 AC 149 ms
4,908 KB
testcase_19 AC 148 ms
4,860 KB
testcase_20 AC 148 ms
4,908 KB
testcase_21 AC 149 ms
4,916 KB
testcase_22 AC 149 ms
5,044 KB
testcase_23 AC 148 ms
5,040 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:5:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-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