Submission #199372

#TimeUsernameProblemLanguageResultExecution timeMemory
199372CaroLindaSkyscraper (JOI16_skyscraper)C++14
5 / 100
1354 ms212020 KiB
#include <bits/stdc++.h> const int MOD = 1e9+7 ; const int MAXL = 110 ; const int MAXN = 15 ; using namespace std ; int n , l ; int f[MAXN] ; long long dp[ (1<<14)+100 ][ MAXL ][ MAXN ] ; bool isOn(int mask, int i) { return ((1<<i)&mask) != 0 ; } int main() { scanf("%d%d", &n , &l ) ; for(int i = 1 ; i <= n ; i++ ) scanf("%d", &f[i]) ; if( n <= 8 ) { sort( f+1, f+1+n ) ; int ans = 0 , soma = 0 ; for(int i = 1 ; i < n ; i++ ) soma += abs( f[i] - f[i+1] ) ; if( soma <= l ) ans ++ ; while( next_permutation( f+1, f+1+n ) ) { soma = 0; for(int i = 1 ; i < n ; i++ ) soma += abs( f[i] - f[i+1] ) ; if( soma <= l ) ans ++ ; } printf("%d\n" , ans ) ; return 0 ; } long long ans = 0LL ; for(int i = l ; i >= 0 ; i-- ) for(int j = 0 ; j < n ; j++ ) dp[ (1<<n)-1 ][i][j] = 1 ; for(int mask = (1<<n) - 2 ; mask > 0 ; mask-- ) { vector<int> off , on ; for(int i = 0 ; i < n ; i++ ) { if( isOn(mask, i) ) on.push_back(i) ; else off.push_back(i) ; } for(int i = 0 ; i <= l ; i++ ) for(int j : on ) for(int k : off) { if( i < abs( f[j+1] - f[k+1] ) ) continue ; dp[mask][i][j] = (dp[mask][i][j] + dp[ mask|(1<<k) ][ i - abs( f[j+1] - f[k+1] ) ][ k ] ) % MOD ; } } for(int i = 0 ; i < n ; i++ ) ans = ( ans + dp[ (1<<i) ][l][i] ) ; printf("%lld\n" , ans ) ; }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n , &l ) ;
     ~~~~~^~~~~~~~~~~~~~~~~~
skyscraper.cpp:20:41: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1 ; i <= n ; i++ ) scanf("%d", &f[i]) ;
                                    ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...