QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#344348#4238. Zero SumThienuTL 3838ms7128kbC++202.6kb2024-03-04 08:42:272024-03-04 08:42:28

Judging History

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

  • [2024-03-04 08:42:28]
  • 评测
  • 测评结果:TL
  • 用时:3838ms
  • 内存:7128kb
  • [2024-03-04 08:42:27]
  • 提交

answer

#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;

using uint = unsigned int;
using ull = unsigned long long;

template<typename C> struct rge{C l, r;};
template<typename C> rge<C> range(C i, C j) { return rge<C>{i, j}; }
template<typename C> ostream& operator<<(ostream &os, rge<C> &r) { os << '{'; for(auto it = r.l; it != r.r; it++) os << "," + (it == r.l) << *it; os << '}'; return os; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '{' << p.first << "," << p.second << '}'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ","; return os << '}'; }
void dbg_out() { cerr << ']' << endl; }
template<typename A> void dbg_out(A H) { cerr << H; dbg_out(); }
template<typename A, typename B, typename... C> void dbg_out(A H, B G, C... T) { cerr << H << ","; dbg_out(G, T...); }
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = [", dbg_out(__VA_ARGS__)
#else
#define debug(...)
#endif

const int N = 35005;

ll dp[2][3*N];

ll mat[N][7];

int BIL = 1'000'000'000;

const int K = 7;

#define body(j) for(int p = 0; p < K; p++) {  if(p <= 2*k) dp[cur^1][j+p] = min(dp[cur^1][j+p], dp[cur][j] + mat[i][p]); } j++;

void solve(){
    int n, k;
    cin >> n >> k;

    for(int i = 0; i < n; i++) {
        for(int j = 0; j <= 2*k; j++) {
            cin >> mat[i][j];
            mat[i][j] -= BIL;
        }
    }

    int cur = 0;
    for(int i = 0; i < n; i++) {
        memset(dp[cur^1], 0, sizeof(dp[cur^1]));
        if(i % 1000 == 0){
            debug(i);
        }
        int llim = max(0, 2*k*i-n*k);
        int rlim = min(n*k, 2*k*i);
        int j = llim;
        while(j & 3 && j <= rlim) {
            body(j)
        }
        while(j + 4 <= rlim) {
            body(j)
        }
        while(j <= rlim) {
            body(j)
        }
        cur ^= 1;
    }
    cout << dp[cur][n*k] + (ll)BIL * n << endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5812kb

input:

3 1
3 14 15
-3 -5 -35
2 71 82

output:

-19

result:

ok 1 number(s): "-19"

Test #2:

score: 0
Accepted
time: 1ms
memory: 6032kb

input:

5 2
1 2 5 14 42
1 2 3 5 8
1 2 4 8 16
1 2 3 4 5
1 2 6 24 120

output:

16

result:

ok 1 number(s): "16"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5836kb

input:

10 2
-904071845 760493887 -478285804 759035367 -680013382
-587322944 665345507 -20509293 103731947 864888628
738633646 936703855 -370523881 301151360 478433861
703775172 -913389861 691762973 -185132991 543994805
-511007159 118916858 891184 349354959 267412081
-663269925 14450557 369277951 237764429 ...

output:

-6259997315

result:

ok 1 number(s): "-6259997315"

Test #4:

score: 0
Accepted
time: 1ms
memory: 6188kb

input:

10 2
-566639283 -281454349 687175663 817449090 928108928
-819788458 -442586076 -451652406 403601435 -168825683
-649266596 187412594 -856159947 476347172 20574258
-390470703 -791341926 -60895976 842388030 507828204
159048971 -531035734 -110061386 255061473 -622553675
767534638 296274618 318355641 -60...

output:

-5863402983

result:

ok 1 number(s): "-5863402983"

Test #5:

score: 0
Accepted
time: 3838ms
memory: 7128kb

input:

35000 2
-323024395 123746159 618869974 -455533063 294962647
9971372 784839881 -906564905 -578266269 944975915
968956358 -576765224 448197684 986539127 -525297570
-745293354 426913995 129954892 255813154 -243728523
-922616050 -983803120 -317189892 362753890 481320837
-626411581 760532893 481031139 14...

output:

-23326299571078

result:

ok 1 number(s): "-23326299571078"

Test #6:

score: -100
Time Limit Exceeded

input:

35000 3
-389986454 -678028773 330282316 582141258 -976039033 415560778 -256794145
891726219 -744524869 671251658 67347457 -91229912 -787543984 364694820
606490044 511500731 766802212 79214055 -745406592 -843185684 -709300461
-806048178 750955329 92731052 -740911920 943335651 -961204999 72788590
5815...

output:


result: