結果

問題 No.596 郵便配達
ユーザー HIR180HIR180
提出日時 2017-11-10 23:32:39
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,479 bytes
コンパイル時間 1,341 ms
コンパイル使用メモリ 160,828 KB
実行使用メモリ 117,832 KB
最終ジャッジ日時 2024-05-03 14:41:43
合計ジャッジ時間 4,946 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 34 ms
85,700 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 33 ms
89,668 KB
testcase_08 AC 177 ms
90,312 KB
testcase_09 WA -
testcase_10 AC 32 ms
89,544 KB
testcase_11 AC 32 ms
89,544 KB
testcase_12 AC 33 ms
89,544 KB
testcase_13 AC 33 ms
89,540 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 32 ms
89,548 KB
testcase_19 AC 32 ms
89,544 KB
testcase_20 AC 302 ms
117,832 KB
testcase_21 AC 303 ms
116,556 KB
testcase_22 AC 304 ms
116,808 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |         scanf("%d%d",&n,&m);
      |         ~~~~~^~~~~~~~~~~~~~
main.cpp:31:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |                 scanf("%d%d",&x[i],&d[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~
main.cpp:36:37: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |                         int a; scanf("%d",&a);
      |                                ~~~~~^~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int AL[7000005],BL[7000005],CL[7000005];
int AR[7000005],BR[7000005],CR[7000005];
int n,m,x[500005],d[500005];
int mn=INF,mx=-INF;
int mn2=INF,mx2=-INF;
int main(){
	rep(i,7000005){
		AR[i]=BR[i]=CR[i]=INF;
	}
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x[i],&d[i]);
		mn=min(mn,x[i]); mn2=min(mn2,x[i]);
		mx=max(mx,x[i]); mx2=max(mx2,x[i]);
		int MN=INF,MX=-INF;
		for(int j=0;j<d[i];j++){
			int a; scanf("%d",&a);
			MN=min(MN,a);
			MX=max(MX,a);
		}
		if(MN>=x[i]);
		else{
			AL[MN] = max(AL[MN],x[i]);
		}
		
		if(MX<=x[i]);
		else{
			AR[MX] = min(AR[MX],x[i]);
		}
		mn=min(mn,MN);
		mx=max(mx,MX);
	}
	int R = 0,ans = min(mx-mn+mx-mn2,mx-mn+mx2-mn);
	for(int i=mn+1;i<=mx;i++){
		ans = min(ans,mx-mn+mx-i+R);
		R = max(R,max(AL[i],CL[i]));
	}
	R = mx;
	for(int i=mx;i>=mn+1;i--){
		ans = min(ans,i-mn+mx-mn+mx-R);
		R = min(R,min(AR[i],CR[i]));
	}
	cout<<ans<<endl;
}
0