답안 #346448

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
346448 2021-01-09T18:46:20 Z CaroLinda Tents (JOI18_tents) C++14
100 / 100
135 ms 71020 KB
#include <bits/stdc++.h>

#define ll long long

const int MAX = 3010 ;
const ll MOD = 1e9+7 ;

using namespace std ;

int N , M ;
ll dp[MAX][MAX] ;

int main()
{
	scanf("%d %d", &N, &M ) ;

	for(int i = 0 ; i <= max(N,M) ; i++ ) dp[0][i] = dp[i][0] = 1 ;

	for(int i= 1 ; i <= N ; i++ )
	{
		ll bin = (ll)i * (i-1)  ;
		bin = (bin>>1LL ) % MOD ;

		ll c = (4*i) % MOD ;

		for(int j = 1 , aux = 0 ; j <= M ; j++, aux += i )
		{
			if( aux >= MOD ) aux -= MOD ;

			ll &ptr = dp[i][j] ;

			ptr = dp[i][j-1] ;
			ptr += ( c * dp[i-1][j-1] ) % MOD ;

			if( ptr >= MOD ) ptr -= MOD ;

			if(i >= 2 )
			{
				ptr += ( bin * dp[i-2][j-1] ) % MOD ;
				if( ptr >= MOD ) ptr -= MOD ;
			}

			if( j >= 2 )
			{
				ptr += ( aux * dp[i-1][j-2] ) % MOD ;
				if( ptr >= MOD ) ptr -= MOD ;
			}

		}

	}


	ll ans = dp[N][M] - 1LL ;

	if( ans < 0 ) ans += MOD ;

	printf("%lld\n", ans ) ;

}

Compilation message

tents.cpp: In function 'int main()':
tents.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |  scanf("%d %d", &N, &M ) ;
      |  ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1536 KB Output is correct
6 Correct 1 ms 1388 KB Output is correct
7 Correct 1 ms 1388 KB Output is correct
8 Correct 1 ms 1516 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 2 ms 1792 KB Output is correct
11 Correct 1 ms 1516 KB Output is correct
12 Correct 2 ms 2176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1536 KB Output is correct
6 Correct 1 ms 1388 KB Output is correct
7 Correct 1 ms 1388 KB Output is correct
8 Correct 1 ms 1516 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 2 ms 1792 KB Output is correct
11 Correct 1 ms 1516 KB Output is correct
12 Correct 2 ms 2176 KB Output is correct
13 Correct 4 ms 7788 KB Output is correct
14 Correct 6 ms 9708 KB Output is correct
15 Correct 91 ms 55276 KB Output is correct
16 Correct 9 ms 9452 KB Output is correct
17 Correct 23 ms 17388 KB Output is correct
18 Correct 26 ms 17920 KB Output is correct
19 Correct 102 ms 62956 KB Output is correct
20 Correct 82 ms 50924 KB Output is correct
21 Correct 56 ms 35564 KB Output is correct
22 Correct 57 ms 35584 KB Output is correct
23 Correct 38 ms 27116 KB Output is correct
24 Correct 135 ms 71020 KB Output is correct
25 Correct 103 ms 61420 KB Output is correct
26 Correct 117 ms 66796 KB Output is correct
27 Correct 130 ms 69356 KB Output is correct