結果

問題 No.1977 Extracting at Constant Intervals
ユーザー ForestedForested
提出日時 2022-06-10 23:42:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 3,574 bytes
コンパイル時間 1,409 ms
コンパイル使用メモリ 133,868 KB
実行使用メモリ 41,344 KB
最終ジャッジ日時 2024-04-17 15:41:12
合計ジャッジ時間 3,267 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 11 ms
7,680 KB
testcase_03 AC 78 ms
37,888 KB
testcase_04 AC 11 ms
7,552 KB
testcase_05 AC 79 ms
41,344 KB
testcase_06 AC 46 ms
23,808 KB
testcase_07 AC 59 ms
30,336 KB
testcase_08 AC 39 ms
24,960 KB
testcase_09 AC 19 ms
11,136 KB
testcase_10 AC 58 ms
32,768 KB
testcase_11 AC 6 ms
5,504 KB
testcase_12 AC 13 ms
8,192 KB
testcase_13 AC 60 ms
30,720 KB
testcase_14 AC 69 ms
37,888 KB
testcase_15 AC 35 ms
19,328 KB
testcase_16 AC 72 ms
37,376 KB
testcase_17 AC 80 ms
41,344 KB
testcase_18 AC 36 ms
19,072 KB
testcase_19 AC 15 ms
10,624 KB
testcase_20 AC 65 ms
33,280 KB
testcase_21 AC 67 ms
34,944 KB
testcase_22 AC 58 ms
38,272 KB
testcase_23 AC 11 ms
8,448 KB
testcase_24 AC 52 ms
34,432 KB
testcase_25 AC 6 ms
5,888 KB
testcase_26 AC 8 ms
7,296 KB
testcase_27 AC 30 ms
19,584 KB
testcase_28 AC 14 ms
11,008 KB
testcase_29 AC 31 ms
20,480 KB
testcase_30 AC 54 ms
36,096 KB
testcase_31 AC 25 ms
17,920 KB
testcase_32 AC 34 ms
19,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef LOCAL
#define FAST_IO
#endif

// ===== template.hpp =====
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define OVERRIDE(a, b, c, d, ...) d
#define REP2(i, n) for (i32 i = 0; i < (i32) (n); ++i)
#define REP3(i, m, n) for (i32 i = (i32) (m); i < (i32) (n); ++i)
#define REP(...) OVERRIDE(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
#define PER(i, n) for (i32 i = (i32) (n) - 1; i >= 0; --i)
#define ALL(x) begin(x), end(x)

using namespace std;

using u32 = unsigned int;
using u64 = unsigned long long;
using u128 = __uint128_t;
using i32 = signed int;
using i64 = signed long long;
using i128 = __int128_t;
using f64 = double;
using f80 = long double;

template <typename T>
using Vec = vector<T>;

template <typename T>
bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}

istream &operator>>(istream &is, i128 &x) {
    i64 v;
    is >> v;
    x = v;
    return is;
}
ostream &operator<<(ostream &os, i128 x) {
    os << (i64) x;
    return os;
}
istream &operator>>(istream &is, u128 &x) {
    u64 v;
    is >> v;
    x = v;
    return is;
}
ostream &operator<<(ostream &os, u128 x) {
    os << (u64) x;
    return os;
}

template <typename F, typename Comp = less<>>
Vec<i32> sort_index(i32 n, F f, Comp comp = Comp()) {
    Vec<i32> idx(n);
    iota(ALL(idx), 0);
    sort(ALL(idx), [&](i32 i, i32 j) -> bool {
        return comp(f(i), f(j));
    });
    return idx;
}

[[maybe_unused]] constexpr i32 INF = 1000000100;
[[maybe_unused]] constexpr i64 INF64 = 3000000000000000100;

#ifdef FAST_IO
__attribute__((constructor)) void fast_io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
}
#endif
// ===== template.hpp =====

#ifdef DEBUGF
#include  "cpl/template/debug.hpp"
#else
#define DBG(x) (void) 0
#endif

int main() {
    i32 n;
    i64 m;
    i64 l;
    cin >> n >> m >> l;
    Vec<i64> a(n);
    REP(i, n) {
        cin >> a[i];
    }
    
    i32 lg = 0;
    while (n * m > (1LL << lg)) {
        ++lg;
    }
    
    i32 step = l % n;
    Vec<i32> steps(lg + 1);
    steps[0] = step;
    REP(i, lg) {
        steps[i + 1] = 2 * steps[i] % n;
    }
    
    Vec<Vec<i64>> gain(lg + 1, Vec<i64>(n));
    gain[0] = a;
    REP(i, lg) {
        REP(j, n) {
            gain[i + 1][j] = gain[i][j] + gain[i][(j + steps[i]) % n];
        }
    }
    DBG(gain);
    
    const auto calc_cx = [&](i64 x) -> i64 {
        i64 cnt = n * m / l;
        if (x < n * m % l) {
            ++cnt;
        }
        DBG(x);
        DBG(cnt);
        i64 sum = 0;
        i32 cur = x % n;
        REP(i, lg + 1) {
            if ((cnt >> i) & 1) {
                sum += gain[i][cur];
                cur = (cur + steps[i]) % n;
            }
        }
        DBG(sum);
        return sum;
    };
    
    i64 ans = -INF64;
    REP(i, n) {
        chmax(ans, calc_cx(i % l));
    }
    if (l > n) {
        for (i64 i = l - n; i < l; ++i) {
            chmax(ans, calc_cx(i));
        }
    }
    for (i64 i = n * m - n; i < n * m; ++i) {
        chmax(ans, calc_cx(i % l));
    }
    cout << ans << '\n';
}
0