結果

問題 No.3044 April Sum of Odd
ユーザー eto_nagisaeto_nagisa
提出日時 2019-04-01 21:40:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,602 bytes
コンパイル時間 1,783 ms
コンパイル使用メモリ 171,416 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-05 04:14:03
合計ジャッジ時間 2,108 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
constexpr int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m; cin >> n >> m;
	vl v(n);
	REP(i, n)cin >> v[i];
	vl tmp;
	vl ans;
	REP(i, n) {
		if (v[i] % 2 == 0) {
			if (tmp.size() >= m) {
				ll res = 0;
				ll sum = 0;
				int t = tmp.size();
				tmp.push_back(0);
				REP(j, m)sum += tmp[j];
				REP(j, t - m + 1) {
					res += sum;
					sum += tmp[j+m];
					sum -= tmp[j];
				}
				ans.push_back(res);
			}
			tmp.clear();
		}
		else {
			tmp.push_back(v[i]);
		}
	}
	if (tmp.size() >= m) {
		ll res = 0;
		ll sum = 0;
		int t = tmp.size();
		tmp.push_back(0);
		REP(j, m)sum += tmp[j];
		REP(j, t - m + 1) {
			res += sum;
			sum += tmp[j + m];
			sum -= tmp[j];
		}
		ans.push_back(res);
	}
	tmp.clear();
	REP(i, ans.size())cout << ans[i] << endl;
}
0