Submission #879606

# Submission time Handle Problem Language Result Execution time Memory
879606 2023-11-27T17:49:04 Z Mr_Husanboy Energetic turtle (IZhO11_turtle) C++17
5 / 100
250 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 = max(ans, dp[n][m][i]);
        }
        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:97:10: warning: variable 'start' set but not used [-Wunused-but-set-variable]
   97 |     auto start = chrono::high_resolution_clock::now();
      |          ^~~~~
turtle.cpp:100:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |         freopen((fileio + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
turtle.cpp:101:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |         freopen((fileio + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Runtime error 1 ms 860 KB Execution killed with signal 11
4 Runtime error 1 ms 1372 KB Execution killed with signal 11
5 Runtime error 13 ms 8832 KB Execution killed with signal 11
6 Incorrect 50 ms 22820 KB Output isn't correct
7 Runtime error 140 ms 92724 KB Execution killed with signal 11
8 Incorrect 250 ms 94308 KB Output isn't correct
9 Runtime error 154 ms 262144 KB Execution killed with signal 9
10 Runtime error 139 ms 262144 KB Execution killed with signal 9
11 Runtime error 134 ms 262144 KB Execution killed with signal 9
12 Runtime error 132 ms 262144 KB Execution killed with signal 9
13 Runtime error 127 ms 262144 KB Execution killed with signal 9
14 Runtime error 128 ms 262144 KB Execution killed with signal 9
15 Runtime error 127 ms 262144 KB Execution killed with signal 9
16 Runtime error 128 ms 262144 KB Execution killed with signal 9
17 Runtime error 125 ms 262144 KB Execution killed with signal 9
18 Runtime error 133 ms 262144 KB Execution killed with signal 9
19 Runtime error 123 ms 262144 KB Execution killed with signal 9
20 Runtime error 127 ms 262144 KB Execution killed with signal 9