답안 #888529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
888529 2023-12-17T16:19:02 Z Frederic_ Tents (JOI18_tents) C++17
100 / 100
1664 ms 71248 KB
#include <bits/stdc++.h> 
using namespace std; 

#define IOS ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) 
#define fort(itr,map) for(auto itr = map.begin(); itr != map.end(); ++itr) 
#define pb push_back 
#define elif else if 
#define F first 
#define S second 
#define all(v) v.begin(), v.end() 
#define uni(v) sort(all(v)), v.erase(unique(all(v)), v.end()) 
#define err_dp(i, j) cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
#define int long long 

const int MAX = 3e3 + 10; 
const int MOD = 1e9 + 7; 

int dp[MAX][MAX]; 

int cu_pow(int a, int b){
    if(b == 1) return a;
    int ans = cu_pow(a, b / 2);
    ans = 1LL * ans * ans; ans = ans % MOD;
    if(b % 2) ans = 1LL * ans * a; ans = ans % MOD;
    return ans % MOD;
}

int comb(int x){
    return 1LL * x * (x - 1) * cu_pow(2, MOD - 2) % MOD;
}

main()
{IOS;

    int n, m; cin >> n >> m;
    for(int i = 0; i <= n; i++) dp[i][0] = 1;
    for(int j = 0; j <= m; j++) dp[0][j] = 1;

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            int res = 1LL * 4 * i * (dp[i - 1][j - 1]); res = res % MOD;
            res = res + (dp[i][j - 1]); res = res % MOD;
            if(i > 1)
                res = res + (1LL * comb(i) * dp[i - 2][j - 1]), res = res % MOD;
            if(j > 1)
                res = res + (1LL * (i * (j - 1))) * dp[i - 1][j - 2], res = res % MOD;

            dp[i][j] = res;
        }
    }

    cout << (dp[n][m] - 1 + MOD) % MOD << endl;

}

Compilation message

tents.cpp: In function 'long long int cu_pow(long long int, long long int)':
tents.cpp:24:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   24 |     if(b % 2) ans = 1LL * ans * a; ans = ans % MOD;
      |     ^~
tents.cpp:24:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   24 |     if(b % 2) ans = 1LL * ans * a; ans = ans % MOD;
      |                                    ^~~
tents.cpp: At global scope:
tents.cpp:32:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   32 | main()
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 3 ms 2396 KB Output is correct
6 Correct 5 ms 6736 KB Output is correct
7 Correct 4 ms 2396 KB Output is correct
8 Correct 4 ms 6580 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 8 ms 8540 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 18 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 3 ms 2396 KB Output is correct
6 Correct 5 ms 6736 KB Output is correct
7 Correct 4 ms 2396 KB Output is correct
8 Correct 4 ms 6580 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 8 ms 8540 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 18 ms 8540 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 7 ms 55868 KB Output is correct
15 Correct 1036 ms 66276 KB Output is correct
16 Correct 68 ms 6736 KB Output is correct
17 Correct 232 ms 16996 KB Output is correct
18 Correct 287 ms 29272 KB Output is correct
19 Correct 1212 ms 70380 KB Output is correct
20 Correct 965 ms 60244 KB Output is correct
21 Correct 638 ms 39760 KB Output is correct
22 Correct 626 ms 51872 KB Output is correct
23 Correct 353 ms 70480 KB Output is correct
24 Correct 1664 ms 71248 KB Output is correct
25 Correct 1236 ms 62184 KB Output is correct
26 Correct 1414 ms 68336 KB Output is correct
27 Correct 1595 ms 70232 KB Output is correct