結果

問題 No.3044 April Sum of Odd
ユーザー furafura
提出日時 2020-04-13 14:38:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 637 bytes
コンパイル時間 2,155 ms
コンパイル使用メモリ 206,248 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 03:42:38
合計ジャッジ時間 3,424 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 16 ms
4,348 KB
testcase_11 AC 11 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

template<class T>
vector<pair<T,int>> run_length_encoding(const vector<T>& a){
	vector<pair<T,int>> res;
	int n=a.size(),pre=0;
	rep(i,n) if(i==n-1 || a[i]!=a[i+1]) res.emplace_back(a[i],i-pre+1), pre=i+1;
	return res;
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<int> a(n),b(n);
	rep(i,n) scanf("%d",&a[i]), b[i]=a[i]%2;

	int pos=0;
	for(auto p:run_length_encoding(b)){
		if(p.first==1 && p.second>=m){
			lint sum=0;
			rep(i,p.second) sum+=a[pos+i];
			printf("%lld\n",sum);
		}
		pos+=p.second;
	}

	return 0;
}
0