QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#166930#6868. Klee likes making friendsPPP#AC ✓350ms19992kbC++171.3kb2023-09-06 21:08:092023-09-06 21:08:11

Judging History

你现在查看的是最新测评结果

  • [2023-09-06 21:08:11]
  • 评测
  • 测评结果:AC
  • 用时:350ms
  • 内存:19992kb
  • [2023-09-06 21:08:09]
  • 提交

answer

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

const ll mod = 1000000007;

#define X first
#define Y second

ll pew(ll a, ll b)
{
    ll res = 1;
    while (b>0)
    {
        if (b&1) res = res*a%mod;
        b >>= 1;
        a = a*a%mod;
    }
}


const int N = 2048;

int dp[N][N];

void solve()
{
    for (int j=0;j<N;j++)
    {
        for (int i=0;i<N;i++) dp[j][i] = mod;
    }
    dp[0][1] = 0;
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i=0;i<n;i++) cin >> a[i];
    int A = mod;
    for (int i=0,i2=0;i<=n;i++,i2=(i2+1)%N)
    {
        for (int d=1;d<k;d++)
        {
            dp[i2][d+1] = min(dp[i2][d+1],dp[i2][d]);
            if ((i+k-d)>n) continue;
            dp[(i2+k-d)%N][k-d] = min(dp[(i2+k-d)%N][k-d],dp[i2][d]+a[i+k-d-1]);
        }
        if (i+k-1>=n) A = min(A,dp[i2][k-(n-i)-1]);
        for (int d=1;d<k;d++) dp[i2][d] = mod;
    }
    cout << A << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//#ifdef DEBUG
//    freopen("input.txt", "r", stdin);
//#endif
    int T = 1;
    cin >> T;
    while (T--) solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 350ms
memory: 19992kb

input:

11
10 9
3 6 5 7 8 8 5 6 4 7
15 4
3034 6855 8797 12515 5315 13315 3021 5948 1618 5781 1305 4266 7634 8049 5990
15 2
6722 6887 1628 19483 16034 5800 2683 3444 10818 11900 13443 5020 11435 1033 4029
15 9
8450 8445 6959 2822 15741 16970 10576 13954 16766 12222 14601 10913 1683 16651 7250
381 30
17958 71...

output:

9
33346
120359
15081
55485
157758
106256
880
1898
657
739

result:

ok 11 lines