# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
199368 | 2020-01-31T18:59:39 Z | CaroLinda | Skyscraper (JOI16_skyscraper) | C++14 | 2000 ms | 171232 KB |
#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 ; } long long solve(int mask, int left, int ant) { if( dp[mask][left][ant] != -1 ) return dp[mask][left][ant] ; if( mask == ( 1<<n )-1 ) return 1 ; dp[mask][left][ant] = 0 ; for(int i = 0 ; i < n ; i++ ) if( !isOn(mask, i) && left >= abs( f[i+1] - f[ant+1] ) ) dp[mask][left][ant] = ( dp[mask][left][ant] + solve( mask|(1<<i) , left - abs(f[i+1]-f[ant+1]) , i ) ) % MOD ; return dp[mask][left][ant] ; } 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 ; memset(dp, -1, sizeof dp ) ; for( int i = 0 ; i < n ; i++ ) ans = ( ans + solve( (1<<i) , l , i ) ) % MOD ; printf("%lld\n" , ans ) ; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 5 ms | 248 KB | Output is correct |
3 | Correct | 6 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 6 ms | 256 KB | Output is correct |
6 | Correct | 6 ms | 376 KB | Output is correct |
7 | Correct | 6 ms | 376 KB | Output is correct |
8 | Correct | 6 ms | 376 KB | Output is correct |
9 | Correct | 6 ms | 376 KB | Output is correct |
10 | Correct | 6 ms | 256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2630 ms | 171232 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Correct | 5 ms | 248 KB | Output is correct |
3 | Correct | 6 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 6 ms | 256 KB | Output is correct |
6 | Correct | 6 ms | 376 KB | Output is correct |
7 | Correct | 6 ms | 376 KB | Output is correct |
8 | Correct | 6 ms | 376 KB | Output is correct |
9 | Correct | 6 ms | 376 KB | Output is correct |
10 | Correct | 6 ms | 256 KB | Output is correct |
11 | Execution timed out | 2630 ms | 171232 KB | Time limit exceeded |
12 | Halted | 0 ms | 0 KB | - |