QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#76619#2562. Fake Plastic Trees 2SortingWA 3ms4872kbC++3.4kb2023-02-11 03:42:462023-02-11 03:42:50

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-11 03:42:50]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:4872kb
  • [2023-02-11 03:42:46]
  • 提交

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;
#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 = 1007 ;
const int MAXK = 57 ;

vector < ll > dp[ MAXN ][ MAXK ] ;
vector < ll > nw[ MAXK ] ;

int n , k ;
ll l , r ;
ll a[ MAXN ] ;
int cnt[ MAXN ] ;
vector < int > v[ MAXN ] ;
map < ll , ll > mn , mx ;

void opt ( vector < ll > &aux ) {
    mn.clear ( ) , mx.clear ( ) ;
    ll len = r - l + 1 ;
    for ( auto x : aux ) {
        if ( mn.find ( x / len ) == mn.end ( ) ) {
            mn[ x / len ] = x ;
        }
        if ( mn[ x / len ] > x ) { mn[ x / len ] = x ; }
        if ( mx[ x / len ] < x ) { mx[ x / len ] = x ; }
    }
    aux.clear ( ) ;
    for ( auto e : mn ) {
        aux.push_back ( e.se ) ;
        if ( e.se != mx[ e.fi ] ) {
            aux.push_back ( mx[ e.fi ] ) ;
        }
    }
}

void dfs ( int x , int prv ) {
    dp[ x ][ 0 ].push_back ( a[ x ] ) ;
    cnt[ x ] = 0 ;
    for ( auto y : v[ x ] ) {
        if ( y == prv ) { continue ; }
        dfs ( y , x ) ;
        for ( int i = 0 ; i <= k ; ++ i ) {
            nw[ i ].clear ( ) ;
        }
        for ( int i = 0 ; i <= cnt[ x ] ; ++ i ) {
            for ( int j = 0 ; j <= cnt[ y ] ; ++ j ) {
                if ( i + j > k ) { break ; }
                for ( auto val1 : dp[ x ][ i ] ) {
                    for ( auto val2 : dp[ y ][ j ] ) {
                        if ( val1 + val2 <= r ) { 
                            nw[ i + j ].push_back ( val1 + val2 ) ;
                        }
                    }
                }
            }
        }
        for ( int i = 0 ; i <= k ; ++ i ) {
            dp[ x ][ i ].clear ( ) ;
            opt ( nw[ i ] ) ;
            for ( auto val : nw[ i ] ) {
                dp[ x ][ i ].push_back ( val ) ;
            }
        }
        cnt[ x ] += cnt[ y ] ;
        if ( cnt[ x ] > k ) { cnt[ x ] = k ; }
    }
    ++ cnt[ x ] ;
    if ( cnt[ x ] > k ) { cnt[ x ] = k ; }
    for ( int i = k ; i >= 0 ; -- i ) {
        for ( auto val : dp[ x ][ i ] ) {
            if ( l <= val && val <= r ) {
                if ( x != 1 ) {
                    dp[ x ][ i + 1 ].push_back ( 0 ) ;
                }
                else {
                    dp[ x ][ i ].push_back ( 0 ) ;
                }
                break ;
            }
        }
    }
}

void solve ( ) {
    cin >> n >> k >> l >> r ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        cin >> a[ i ] ;
        v[ i ].clear ( ) ;
        for ( int j = 0 ; j <= k ; ++ j ) {
            dp[ i ][ j ].clear ( ) ;
        }
    }
    for ( int i = 1 , x , y ; i < n ; ++ i ) {
        cin >> x >> y ;
        v[ x ].push_back ( y ) ;
        v[ y ].push_back ( x ) ;
    }
    dfs ( 1 , -1 ) ;
    for ( int i = 0 ; i <= k ; ++ i ) {
        bool fl = false ;
        for ( auto x : dp[ 1 ][ i ] ) {
            if ( x == 0 ) {
                fl = true ;
                break ;
            }
        }
        if ( fl == true ) { cout << "1" ; }
        else { cout << "0" ; }
    }
    cout << "\n" ;
}

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

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 4872kb

input:

3
4 3 1 2
1 1 1 1
1 2
2 3
3 4
4 3 1 2
1 1 1 1
1 2
1 3
1 4
4 3 0 0
1 1 1 1
1 2
1 3
1 4

output:

0111
0011
0000

result:

ok 3 tokens

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 4700kb

input:

100
10 9 18 50
18 0 9 8 11 11 13 16 9 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 38 50
4 10 11 13 19 6 14 14 20 14
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 26 50
6 1 12 7 1 12 20 2 0 12
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 29 50
16 13 1 17 20 15 0 3 6 7
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10...

output:

0011000000
0010000000
0100000000
0010000000
0011111000
0111100000
0010000000
0010000000
0100000000
0011111000
0110000000
0011000000
0011111100
0100000000
0010000000
0010000000
0010000000
0011000000
0111000000
0011100000
0100000000
0100000000
0100000000
0011000000
0011000000
0011111000
0011111110
001...

result:

wrong answer 50th words differ - expected: '0011100000', found: '0011110000'