/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 532.0 KiB
#2 Wrong Answer 1ms 528.0 KiB
#3 Wrong Answer 323ms 1.449 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],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:27:46
Judged At
2024-11-11 03:28:54
Judged By
Score
5
Total Time
323ms
Peak Memory
1.449 MiB