QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#77112#2573. Two PermutationsSortingWA 2ms3476kbC++2.1kb2023-02-13 03:43:242023-02-13 03:43:25

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-13 03:43:25]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3476kb
  • [2023-02-13 03:43:24]
  • 提交

answer

#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair < int , int > pii ; 
typedef vector<int> vi;
typedef unsigned int uint ;
#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 MOD = 1e9 + 7 ;
const int MAXN = 107 ;

int n , k ;
ll dp[ 2 ][ MAXN * MAXN ][ MAXN ] ;

void solve ( ) {
    cin >> n >> k ;
    int prv = 0 , nxt = 1 ;
    dp[ prv ][ 0 ][ 0 ] = 1 ;
    for ( int i = n ; i >= 1 ; -- i ) {
        for ( int sm = 0 ; sm <= k ; ++ sm ) {
            for ( int j = 0 ; j <= n ; ++ j ) {
                if ( dp[ prv ][ sm ][ j ] == 0 ) { continue ; }
                ll emp = i , half = ( n - i ) - j ;
                // matching
                if ( emp >= 1 ) {
                    dp[ nxt ][ sm + i ][ j + 1 ] += dp[ prv ][ sm ][ j ] * emp ;
                    dp[ nxt ][ sm + i ][ j + 1 ] %= MOD ;
                }
                // both covered
                if ( half >= 1 ) { 
                    dp[ nxt ][ sm ][ j + 2 ] += dp[ prv ][ sm ][ j ] * half * half ;
                    dp[ nxt ][ sm ][ j + 2 ] %= MOD ;
                }
                // one side covered
                if ( half >= 1 && emp >= 1 ) {
                    dp[ nxt ][ sm + i ][ j + 1 ] += 2 * dp[ prv ][ sm ][ j ] * half * emp ;
                    dp[ nxt ][ sm + i ][ j + 1 ] %= MOD ;
                }
                // both sides empty
                if ( emp >= 2 ) {
                    dp[ nxt ][ sm + 2 * i ][ j ] += dp[ prv ][ sm ][ j ] * emp * ( emp - 1 ) ;
                    dp[ nxt ][ sm + 2 * i ][ j ] %= MOD ;
                }
                dp[ prv ][ sm ][ j ] = 0 ;
            }
        }
        prv ^= 1 , nxt ^= 1 ;
    }
    cout << dp[ prv ][ k ][ n ] << "\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: 2ms
memory: 3372kb

input:

2 4

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3428kb

input:

3 7

output:

12

result:

ok 1 number(s): "12"

Test #3:

score: 0
Accepted
time: 2ms
memory: 3476kb

input:

4 10

output:

24

result:

ok 1 number(s): "24"

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 3420kb

input:

4 14

output:

288

result:

wrong answer 1st numbers differ - expected: '96', found: '288'