結果

問題 No.8044 April Sum of Odd
ユーザー fura
提出日時 2020-04-13 14:38:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 637 bytes
コンパイル時間 2,214 ms
コンパイル使用メモリ 196,552 KB
最終ジャッジ日時 2025-01-09 18:00:39
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:17:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |         int n,m; scanf("%d%d",&n,&m);
      |                  ~~~~~^~~~~~~~~~~~~~
main.cpp:19:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   19 |         rep(i,n) scanf("%d",&a[i]), b[i]=a[i]%2;
      |                  ~~~~~^~~~~~~~~~~~

ソースコード

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