답안 #888528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
888528 2023-12-17T16:17:13 Z vjudge1 Tents (JOI18_tents) C++17
100 / 100
1661 ms 71032 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 600 KB Output is correct
2 Correct 0 ms 348 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 6492 KB Output is correct
7 Correct 4 ms 2560 KB Output is correct
8 Correct 5 ms 6492 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 9 ms 8652 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 600 KB Output is correct
2 Correct 0 ms 348 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 6492 KB Output is correct
7 Correct 4 ms 2560 KB Output is correct
8 Correct 5 ms 6492 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 9 ms 8652 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 9 ms 55900 KB Output is correct
15 Correct 1045 ms 66136 KB Output is correct
16 Correct 67 ms 6724 KB Output is correct
17 Correct 233 ms 17016 KB Output is correct
18 Correct 287 ms 29284 KB Output is correct
19 Correct 1202 ms 70232 KB Output is correct
20 Correct 964 ms 60116 KB Output is correct
21 Correct 635 ms 39588 KB Output is correct
22 Correct 629 ms 51872 KB Output is correct
23 Correct 354 ms 70408 KB Output is correct
24 Correct 1661 ms 71032 KB Output is correct
25 Correct 1236 ms 62184 KB Output is correct
26 Correct 1414 ms 68340 KB Output is correct
27 Correct 1595 ms 70392 KB Output is correct