結果

問題 No.1977 Extracting at Constant Intervals
ユーザー magstamagsta
提出日時 2022-05-14 20:37:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,853 bytes
コンパイル時間 1,613 ms
コンパイル使用メモリ 171,648 KB
実行使用メモリ 7,692 KB
最終ジャッジ日時 2023-09-30 13:32:16
合計ジャッジ時間 4,145 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 10 ms
4,380 KB
testcase_03 AC 39 ms
5,156 KB
testcase_04 AC 11 ms
4,376 KB
testcase_05 AC 61 ms
5,104 KB
testcase_06 AC 27 ms
5,208 KB
testcase_07 AC 35 ms
6,060 KB
testcase_08 AC 34 ms
5,444 KB
testcase_09 AC 17 ms
4,380 KB
testcase_10 AC 44 ms
4,376 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 48 ms
6,536 KB
testcase_14 AC 85 ms
7,648 KB
testcase_15 AC 30 ms
5,340 KB
testcase_16 AC 67 ms
7,352 KB
testcase_17 AC 62 ms
4,688 KB
testcase_18 AC 26 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 35 ms
5,212 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 34 ms
5,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long gcd(long long x, long long y) {
	if (x < y) swap(x, y);
	while (y > 0) {
		long long r = x % y;
		x = y;
		y = r;
	}
	return x;
}

long long lcm(long long x, long long y) {
	return x * y / gcd(x, y);
}

long long solve(vector<long long> A, long long M, long long L) {
	long long N = A.size();

	vector<long long> rui(2 * N);
	rui[0] = A[0];
	for (int i = 1; i < 2 * N; i++) {
		rui[i] = rui[i - 1] + A[(i * (L % N)) % N];
	}

	if (L <= N) {
		long long sum = 0;
		for (int i = 0; i < N; i++) {
			sum += A[i];
		}
		vector<long long> ans(L, (M / L) * sum);
		M %= L;
		for (int i = 0; i < N; i++) {
			if ((i * L) % N < L && N * M - 1 - (i * L) % N >= 0) {
				ans[(i * L) % N] += rui[i + (N * M - 1 - (i * L) % N) / L] - rui[i] + A[(i * L) % N];
			}
		}
		long long max_ = -1000000000000000000;
		for (int i = 0; i < L; i++) {
			max_ = max(max_, ans[i]);
		}
		return max_;
	}

	else {
		long long sum = 0;
		for (int i = 0; i < N; i++) {
			sum += A[i];
		}
		vector<long long> ans2(N, (M / L) * sum);
		M %= L;
		for (int i = 0; i < N; i++) {
			if (N * (M - (L - (i * (L % N)) % N - 1) / N) - 1 - (i * (L % N)) % N >= 0) {
				ans2[(i * (L % N)) % N] += rui[i + (N * (M - (L - (i * (L % N)) % N - 1) / N) - 1 - (i * (L % N)) % N) / L] - rui[i] + A[(i * (L % N)) % N];
			}
		}
		long long max_ = -1000000000000000000;
		for (int i = 0; i < N; i++) {
			max_ = max(max_, ans2[i]);
		}
		return max_;
	}
}

int main() {
	long long N, M, L; cin >> N >> M >> L;
	vector<long long> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	long long max_ = -1000000000000000000;
	for (int i = 0; i < gcd(N, L); i++) {
		vector<long long> B;
		for (int j = 0; j < N / gcd(N, L); j++) {
			B.push_back(A[j * gcd(N, L) + i]);
		}
		max_ = max(max_, solve(B, M, L / gcd(N, L)));
	}

	cout << max_ << endl;
}
0