結果

問題 No.1973 Divisor Sequence
ユーザー 👑 NachiaNachia
提出日時 2022-06-11 00:35:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,743 bytes
コンパイル時間 792 ms
コンパイル使用メモリ 79,960 KB
実行使用メモリ 7,156 KB
最終ジャッジ日時 2023-10-21 06:36:51
合計ジャッジ時間 1,826 ms
ジャッジサーバーID
(参考情報)
judge15 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(int)(n); i++)


const i64 INF = 1001001001001001001;
using modint = atcoder::static_modint<1000000007>;

int GCD(i64 a, i64 b){ return b ? GCD(b, a%b) : a; }


int main(){
    i64 N,M,L; cin >> N >> M >> L;
    vector<i64> A(N);
    rep(i,N) cin >> A[i];
    i64 B = GCD(N, L);
    i64 NbyB = N/B;

    i64 full_length = N * M;

    i64 ans = -INF * 2;

    vector<i64> permA(NbyB);
    vector<i64> indexPermA(NbyB);
    vector<i64> sum_permA(NbyB + 1);

    auto sum_permA_wide = [&](i64 l, i64 r) -> i64 {
        i64 lf = l % NbyB, rf = r % NbyB;
        i64 lH = l / NbyB, rH = r / NbyB;
        return sum_permA[rf] - sum_permA[lf] + (rH - lH) * sum_permA[NbyB];
    };

    rep(t,NbyB) indexPermA[t] = L%N*t%N;
    rep(s,B){
        rep(t,NbyB) permA[t] = A[s + indexPermA[t]];
        rep(t,NbyB) sum_permA[t+1] = sum_permA[t] + permA[t];
        
        rep(t,NbyB){
            i64 s_idx = s + indexPermA[t];
            if(L <= s) continue;
            i64 min_l_idx = s_idx;
            i64 max_l_idx = (L - s_idx - 1) / NbyB * NbyB + s_idx;
            if(min_l_idx > max_l_idx) continue;
            ans = max(ans, sum_permA_wide(t, t + (full_length - 1 - min_l_idx) / L + 1));
            ans = max(ans, sum_permA_wide(t, t + (full_length - 1 - max_l_idx) / L + 1));
        }
    }

    cout << ans << '\n';

    return 0;
}


struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;


0