/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 328.0 KiB
#2 Wrong Answer 2ms 328.0 KiB
#3 Wrong Answer 378ms 1.426 MiB

Code

/*
 *   Copyright (c) 2024 Emon Thakur
 *   All rights reserved.
 */
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'

void solve()
{
    int n,k; cin>>n>>k;
    vector<int>a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<vector<int>> l(n,vector<int>(n)),r(n,vector<int>(n));

    int best;
    for(int i=0;i<n-1;i++)
    {
        best = a[i];
        //if(a[i]==1) continue;
        for(int j=n-1;j>i;j--)
        {
            if(__gcd(a[i],a[j])>1)
            {
                best = max(best,a[j]);
            }
            r[i][j-i] = best;
        }
    }

    for(int i=1;i<n;i++)
    {
        best = a[i];
        for(int j=0;j<i;j++)
        {
            if(__gcd(a[i],a[j])>1)
            {
                best = max(best,a[j]);
            }
            l[i][i-j]=best;
        }
    }

    /*for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++) cout<<l[i][j]<<" ";
        cout<<endl;
    }*/
    long long sum=0,ans=0;
    for(int i=0;i<=n-k;i++)
    {
        sum = 0;
        for(int j=0;j<k;j++)
        {
            sum += max({a[i+j],l[i+j][j+1],r[i+j][k-j]});
        }
        ans = max(ans,sum);
    }
    cout<<ans<<endl;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int t; cin>>t; while(t--) solve();
}

Information

Submit By
Type
Submission
Problem
P1063 Another Maximum Sum in Subarray
Language
C++20 (G++ 13.2.0)
Submit At
2024-06-13 17:28:43
Judged At
2024-11-11 03:28:53
Judged By
Score
5
Total Time
378ms
Peak Memory
1.426 MiB