Submission #112871

# Submission time Handle Problem Language Result Execution time Memory
112871 2019-05-22T11:09:37 Z Mercenary Tents (JOI18_tents) C++14
100 / 100
120 ms 71076 KB
#include<bits/stdc++.h>

using namespace std;
#define taskname "A"
#define pb	push_back
#define mp 	make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 3e3 + 5;
const int mod = 1e9 + 7;

ll dp[maxn][maxn];
int n , m;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> m;
    for(int i = 0 ; i < maxn ; ++i)dp[i][0] = dp[0][i] = 1;
    for(int i = 1 ; i <= n ; ++i){
        for(int j = 1 ; j <= m ; ++j){
            if(i > 1 && j > 1){
                dp[i][j] =  dp[i][j - 1] +
                            dp[i - 1][j - 1] * i * 4 +
                            dp[i - 2][j - 1] * i * (i - 1) / 2 +
                            dp[i - 1][j - 2] * i * (j - 1);
            }
            else if(i > 1){
                dp[i][j] =  dp[i][j - 1] +
                            dp[i - 1][j - 1] * i * 4 +
                            dp[i - 2][j - 1] * i * (i - 1) / 2;
            }else if(j > 1){
                dp[i][j] =  dp[i][j - 1] +
                            dp[i - 1][j - 1] * i * 4 +
                            dp[i - 1][j - 2] * i * (j - 1);
            }else{
                dp[i][j] =  dp[i][j - 1] +
                            dp[i - 1][j - 1] * i * 4;
            }
            if(dp[i][j] >= mod)dp[i][j] %= mod;
        }
    }
    cout << dp[n][m] - 1;
}

Compilation message

tents.cpp: In function 'int main()':
tents.cpp:25:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
tents.cpp:26:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12544 KB Output is correct
2 Correct 10 ms 12544 KB Output is correct
3 Correct 10 ms 12544 KB Output is correct
4 Correct 10 ms 12544 KB Output is correct
5 Correct 10 ms 12672 KB Output is correct
6 Correct 10 ms 12672 KB Output is correct
7 Correct 10 ms 12672 KB Output is correct
8 Correct 11 ms 12672 KB Output is correct
9 Correct 10 ms 12544 KB Output is correct
10 Correct 10 ms 12800 KB Output is correct
11 Correct 10 ms 12544 KB Output is correct
12 Correct 11 ms 13184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12544 KB Output is correct
2 Correct 10 ms 12544 KB Output is correct
3 Correct 10 ms 12544 KB Output is correct
4 Correct 10 ms 12544 KB Output is correct
5 Correct 10 ms 12672 KB Output is correct
6 Correct 10 ms 12672 KB Output is correct
7 Correct 10 ms 12672 KB Output is correct
8 Correct 11 ms 12672 KB Output is correct
9 Correct 10 ms 12544 KB Output is correct
10 Correct 10 ms 12800 KB Output is correct
11 Correct 10 ms 12544 KB Output is correct
12 Correct 11 ms 13184 KB Output is correct
13 Correct 12 ms 12544 KB Output is correct
14 Correct 10 ms 12672 KB Output is correct
15 Correct 78 ms 56108 KB Output is correct
16 Correct 14 ms 15240 KB Output is correct
17 Correct 25 ms 22272 KB Output is correct
18 Correct 29 ms 24568 KB Output is correct
19 Correct 91 ms 63520 KB Output is correct
20 Correct 73 ms 53296 KB Output is correct
21 Correct 52 ms 39288 KB Output is correct
22 Correct 55 ms 38904 KB Output is correct
23 Correct 33 ms 27128 KB Output is correct
24 Correct 117 ms 71076 KB Output is correct
25 Correct 108 ms 62896 KB Output is correct
26 Correct 105 ms 67612 KB Output is correct
27 Correct 120 ms 69368 KB Output is correct