QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#344486#4238. Zero SumSortingWA 52ms4932kbC++201.6kb2024-03-04 17:30:452024-03-04 17:30:46

Judging History

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

  • [2024-03-04 17:30:46]
  • 评测
  • 测评结果:WA
  • 用时:52ms
  • 内存:4932kb
  • [2024-03-04 17:30:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair < int , int > pii ;
typedef vector < int > vi ;
#define fi first
#define se second
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

const int MAXN = 4e4 + 7 ;
const int lim = 302 ;
const ll inf = 1e18 ;

int n , k ;

int perm[ MAXN ] ;
int vals[ MAXN ][ 8 ] ;
ll dp[ 2 ][ 2 * lim ] ;

void solve ( ) {
    cin >> n >> k ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        for ( int j = 1 ; j <= 2 * k + 1 ; ++ j ) {
            cin >> vals[ i ][ j ] ;
        }
        perm[ i ] = i ;
    }
    random_shuffle ( perm + 1 , perm + n + 1 ) ;
    int prv = 0 , nxt = 1 ;
    for ( int i = 0 ; i < 2 * lim ; ++ i ) {
        dp[ prv ][ i ] = dp[ nxt ][ i ] = inf ;
    }
    dp[ prv ][ lim ] = 0 ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        for ( int x = -k ; x <= k ; ++ x ) {
            int add = vals[ perm[ i ] ][ x + k + 1 ] ;
            for ( int j = 0 ; j < 2 * lim ; ++ j ) {
                if ( j + x < 0 || j + x >= 2 * lim ) { continue ; }
                dp[ nxt ][ j + x ] = min ( dp[ nxt ][ j + x ] , dp[ prv ][ j ] + add ) ;
            }
        }
        for ( int j = 0 ; j < 2 * lim ; ++ j ) {
            dp[ prv ][ j ] = inf ;
        }
        prv ^= 1 , nxt ^= 1 ;
    }
    cout << dp[ prv ][ lim ] << "\n" ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t = 1 ; // cin >> t ;
    while ( t -- ) { solve ( ) ; }
    return 0 ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3628kb

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: 0ms
memory: 3772kb

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: 0ms
memory: 3700kb

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: 0ms
memory: 3692kb

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: -100
Wrong Answer
time: 52ms
memory: 4932kb

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:

-23326279777061

result:

wrong answer 1st numbers differ - expected: '-23326299571078', found: '-23326279777061'