답안 #879602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879602 2023-11-27T17:43:46 Z Mr_Husanboy 힘 센 거북 (IZhO11_turtle) C++17
5 / 100
215 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;



#ifdef LOCAL
#include "debugger.cpp"
#else
#define debug(...)
#endif
template<class T>
int len(T &a){
    return a.size();
}

using ll = long long;
using pii = pair<int,int>;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
string fileio = "";


mt19937 mt(time(nullptr));
const int inf = 1e9;
const ll infl = 1e18;
const int maxn = 1e5 + 1;





void solve(){
    int n, m, k, t, mod;
    cin >> n >> m >> k >> t >> mod;
    vector<pair<int,int>> p(k);
    for(auto &[a,b] : p) cin >> a >> b;
    auto brute = [&](){
        int dp[m + 1][n + 1][t + 1]{};
        map<pair<int,int>, int> mp;
        for(int i = 0; i < k; i ++){
            auto [x,y] = p[i];
            mp[{y,x}] = 1;
        }
        dp[0][0][0] = 1;
        for(int i = 1; i <= n; i ++){
            if(mp[{0, i}]){
                for(int j = 1; j <= t; j ++) {
                    dp[0][i][j] += dp[0][i - 1][j - 1];
                    if(dp[0][i][j] >= mod) dp[0][i][j] -= mod;
                }
            }else{
                for(int j = 0; j <= t; j ++) {
                    dp[0][i][j] += dp[0][i - 1][j];
                    if(dp[0][i][j] >= mod) dp[0][i][j] -= mod;
                }
            }
        }
        for(int i = 1; i <= m; i ++){
            if(mp[{i, 0}]){
                for(int j = 1; j <= t; j ++) {
                    dp[i][0][j] += dp[i - 1][0][j - 1];
                    if(dp[i][0][j] >= mod) dp[i][0][j] -= mod;
                }
            }else{
                for(int j = 0; j <= t; j ++) {
                    dp[i][0][j] += dp[i - 1][0][j];
                    if(dp[i][0][j] >= mod) dp[i][0][j] -= mod;
                }
            }
            for(int j = 1; j <= n; j ++){
                if(mp[{i, j}]){
                    for(int u = 1; u <= t; u ++){
                        dp[i][j][u] = dp[i][j - 1][u - 1] + dp[i - 1][j][u - 1];
                        if(dp[i][j][u] >= mod) dp[i][j][u] -= mod;
                    }
                }else{
                    for(int u = 0; u <= t; u ++){
                        dp[i][j][u] = dp[i][j - 1][u] + dp[i - 1][j][u];
                        if(dp[i][j][u] >= mod) dp[i][j][u] -= mod;
                    }
                }
            }

        }
        int ans = 0;
        for(int i = 0; i <= t; i ++){
            ans += dp[n][m][t];
            if(ans >= mod) ans -= mod;
        }
        cout << ans;
    };

    brute();
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    auto start = chrono::high_resolution_clock::now();
    #ifndef LOCAL
    if(fileio.size()){
        freopen((fileio + ".in").c_str(), "r", stdin);
        freopen((fileio + ".out").c_str(), "w", stdout);
    }
    #endif
    int testcases = 1;
    #ifdef Tests
    cin >> testcases;
    #endif
    while(testcases --){
        solve();
        cout << '\n';
        #ifdef LOCAL
        cout << "_________________________" << endl;
        #endif
    }
    #ifdef LOCAL
    auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start);
    
    cout << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl;
    #endif
    return 0;
}

Compilation message

turtle.cpp: In function 'int main()':
turtle.cpp:99:10: warning: variable 'start' set but not used [-Wunused-but-set-variable]
   99 |     auto start = chrono::high_resolution_clock::now();
      |          ^~~~~
turtle.cpp:102:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |         freopen((fileio + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
turtle.cpp:103:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  103 |         freopen((fileio + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 444 KB Output isn't correct
3 Runtime error 1 ms 856 KB Execution killed with signal 11
4 Runtime error 2 ms 1372 KB Execution killed with signal 11
5 Runtime error 10 ms 8796 KB Execution killed with signal 11
6 Incorrect 52 ms 22868 KB Output isn't correct
7 Runtime error 126 ms 92872 KB Execution killed with signal 11
8 Incorrect 215 ms 94424 KB Output isn't correct
9 Runtime error 146 ms 262144 KB Execution killed with signal 9
10 Runtime error 131 ms 262144 KB Execution killed with signal 9
11 Runtime error 127 ms 262144 KB Execution killed with signal 9
12 Runtime error 150 ms 262144 KB Execution killed with signal 9
13 Runtime error 135 ms 262144 KB Execution killed with signal 9
14 Runtime error 126 ms 262144 KB Execution killed with signal 9
15 Runtime error 126 ms 262144 KB Execution killed with signal 9
16 Runtime error 127 ms 262144 KB Execution killed with signal 9
17 Runtime error 135 ms 262144 KB Execution killed with signal 9
18 Runtime error 132 ms 262144 KB Execution killed with signal 9
19 Runtime error 129 ms 262144 KB Execution killed with signal 9
20 Runtime error 128 ms 262144 KB Execution killed with signal 9