結果

問題 No.738 平らな農地
ユーザー 👑 kmjpkmjp
提出日時 2018-09-28 22:35:32
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,734 bytes
コンパイル時間 1,712 ms
コンパイル使用メモリ 164,304 KB
実行使用メモリ 21,988 KB
最終ジャッジ日時 2024-04-20 11:15:37
合計ジャッジ時間 7,445 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
15,884 KB
testcase_01 AC 5 ms
17,760 KB
testcase_02 AC 4 ms
15,880 KB
testcase_03 AC 5 ms
17,764 KB
testcase_04 AC 5 ms
17,760 KB
testcase_05 AC 6 ms
17,788 KB
testcase_06 AC 6 ms
17,656 KB
testcase_07 AC 7 ms
17,820 KB
testcase_08 AC 5 ms
17,776 KB
testcase_09 AC 5 ms
15,752 KB
testcase_10 AC 5 ms
17,640 KB
testcase_11 AC 5 ms
17,900 KB
testcase_12 AC 4 ms
15,744 KB
testcase_13 AC 6 ms
17,652 KB
testcase_14 AC 5 ms
17,648 KB
testcase_15 AC 48 ms
18,960 KB
testcase_16 AC 49 ms
19,976 KB
testcase_17 AC 54 ms
19,944 KB
testcase_18 AC 54 ms
18,908 KB
testcase_19 AC 63 ms
19,260 KB
testcase_20 AC 50 ms
18,964 KB
testcase_21 AC 61 ms
21,988 KB
testcase_22 AC 54 ms
19,228 KB
testcase_23 AC 60 ms
21,984 KB
testcase_24 AC 59 ms
18,824 KB
testcase_25 AC 5 ms
17,772 KB
testcase_26 AC 5 ms
15,904 KB
testcase_27 AC 5 ms
17,772 KB
testcase_28 AC 5 ms
15,904 KB
testcase_29 AC 5 ms
17,768 KB
testcase_30 AC 5 ms
15,896 KB
testcase_31 AC 5 ms
17,904 KB
testcase_32 AC 5 ms
17,768 KB
testcase_33 AC 5 ms
17,900 KB
testcase_34 AC 5 ms
15,896 KB
testcase_35 AC 5 ms
15,644 KB
testcase_36 AC 5 ms
15,636 KB
testcase_37 AC 5 ms
15,900 KB
testcase_38 AC 6 ms
17,636 KB
testcase_39 AC 5 ms
15,888 KB
testcase_40 AC 5 ms
15,904 KB
testcase_41 AC 5 ms
17,772 KB
testcase_42 AC 5 ms
15,888 KB
testcase_43 AC 5 ms
15,884 KB
testcase_44 AC 5 ms
15,768 KB
testcase_45 AC 50 ms
18,904 KB
testcase_46 AC 48 ms
19,616 KB
testcase_47 AC 50 ms
19,368 KB
testcase_48 AC 46 ms
19,972 KB
testcase_49 AC 44 ms
18,952 KB
testcase_50 AC 46 ms
19,484 KB
testcase_51 AC 53 ms
19,180 KB
testcase_52 AC 48 ms
19,744 KB
testcase_53 AC 49 ms
19,024 KB
testcase_54 AC 52 ms
19,240 KB
testcase_55 AC 51 ms
19,372 KB
testcase_56 AC 53 ms
19,336 KB
testcase_57 AC 47 ms
18,932 KB
testcase_58 AC 49 ms
19,572 KB
testcase_59 AC 49 ms
19,204 KB
testcase_60 AC 48 ms
19,916 KB
testcase_61 AC 48 ms
20,764 KB
testcase_62 AC 45 ms
20,728 KB
testcase_63 AC 52 ms
20,796 KB
testcase_64 AC 52 ms
19,140 KB
testcase_65 AC 67 ms
19,436 KB
testcase_66 AC 72 ms
19,136 KB
testcase_67 AC 39 ms
19,532 KB
testcase_68 AC 39 ms
18,696 KB
testcase_69 AC 49 ms
19,336 KB
testcase_70 AC 48 ms
18,976 KB
testcase_71 AC 50 ms
19,872 KB
testcase_72 AC 48 ms
19,224 KB
testcase_73 AC 42 ms
19,456 KB
testcase_74 AC 50 ms
19,488 KB
testcase_75 WA -
testcase_76 AC 49 ms
19,552 KB
testcase_77 AC 53 ms
19,204 KB
testcase_78 AC 58 ms
19,816 KB
testcase_79 AC 52 ms
19,184 KB
testcase_80 AC 48 ms
19,268 KB
testcase_81 AC 49 ms
19,560 KB
testcase_82 AC 52 ms
19,088 KB
testcase_83 AC 47 ms
20,196 KB
testcase_84 AC 50 ms
19,280 KB
testcase_85 AC 71 ms
19,672 KB
testcase_86 AC 62 ms
19,060 KB
testcase_87 AC 35 ms
20,436 KB
testcase_88 AC 34 ms
18,744 KB
testcase_89 AC 4 ms
17,764 KB
testcase_90 AC 4 ms
15,756 KB
testcase_91 AC 5 ms
15,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<class V, int ME> class BIT {
public:
	V bit[1<<ME],val[1<<ME];
	V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	void add(int e,V v) { val[e++]+=v; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
	void set(int e,V v) { add(e,v-val[e]);}
	int lower_bound(V val) {
		V tv=0; int i,ent=0;
		for(i=ME-1;i>=0;i--) if(tv+bit[ent+(1<<i)-1]<val) tv+=bit[ent+(1<<i)-1],ent+=(1<<i);
		return ent;
	}
};
BIT<ll,20> num,tot;

int N,K;
int A[101010];
int R[101010];
pair<int,int> P[101010];

ll hoge() {
	int p=(K+1)/2;
	int x=num.lower_bound(p);
	
	ll ret=0;
	ret+=(p-1)*P[x].first-tot(x-1);
	ret+=(tot(N)-tot(x))-(K-p)*P[x].first;
	return ret;
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	FOR(i,N) {
		cin>>A[i];
		P[i]={A[i],i};
	}
	sort(P,P+N);
	FOR(i,N) R[P[i].second]=i;
	
	ll mi=1LL<<60;
	FOR(i,K-1) {
		num.add(R[i],1);
		tot.add(R[i],A[i]);
	}
	for(i=0;i+K<=N;i++) {
		num.add(R[i+K-1],1);
		tot.add(R[i+K-1],A[i+K-1]);
		mi=min(mi,hoge());
		num.add(R[i],-1);
		tot.add(R[i],-A[i]);
	}
	cout<<mi<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0