Submission #1073135

# Submission time Handle Problem Language Result Execution time Memory
1073135 2024-08-24T09:48:12 Z coolboy19521 Energetic turtle (IZhO11_turtle) C++17
45 / 100
119 ms 1756 KB
// Thanks Benq
 
#include "bits/stdc++.h"
#define ll long long
#define int ll
 
using namespace std;
 
const int sz = 6e5 + 2;
const int sm = 100;
 
vector<pair<int,int>> vp;
vector<int> ps;
ll wz[sm][sm];
ll dp[sm][sm];
bool sv[sz];
int MOD;
 
ll bpw(ll x, ll b, ll z) {
    ll r = 1;
    while (b) {
        if (b & 1)
            (r *= x) %= z;
        (x *= x) %= z;
        b >>= 1;
    }
    return r;
}
 
int mod(ll x){
	while(x<0)	
		x+=MOD;
	return (x%MOD);	
}
int Fe(int x,int y){
	if(!y)
		return 1;
	int h=Fe(x,y/2);
	h=mod(h*1LL*h);
	if(y&1)
		h=mod(h*1LL*x);
	return h;	
}
int cnt(int x,int p){
	int res=0;
	while(x){
		x/=p;
		res+=x;
	}
	return res;	
}
int C(int x,int y){
    if (y == x || 0 == y) return 1;
    if (1 == y || x - 1 == y) return x;
    if (y > x) return 0;
	int ans=1;
    for (auto p : ps) {
		int pw=cnt(x,p)-cnt(y,p)-cnt(x-y,p);
		ans=mod(ans*1LL*Fe(p,pw));
	}
	return ans;
}
 
ll gt(pair<int,int>& f, pair<int,int>& s, int z) {
    int xds = s.first - f.first;
    int yds = s.second - f.second;
    return C(xds + yds, yds);
}
 
ll sb(ll a, ll b, ll z) {
    return (a + z - b) % z;
}
 
ll ml(ll a, ll b, ll z) {
    return a * b % z;
}
 
ll ad(ll a, ll b, ll z) {
    return (a + b) % z;
}
 
signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
 
    ll n, m, k, t, z;
    cin >> n >> m >> k >> t >> z;
    MOD = z;
    int sd = sz;
 
    for (ll i = 2; i < sd; i ++) {
        if (sv[i]) continue;
        ps.push_back(i);
        sv[i] = true;
        for (ll j = i * i; j < sd; j += i)
            sv[j] = true;
    }
 
    for (int i = 0; i < k; i ++) {
        int x, y;
        cin >> x >> y;
        vp.push_back(make_pair(x, y));
    }
 
    vp.push_back(make_pair(0, 0));
    vp.push_back(make_pair(n, m));
 
    sort(begin(vp), end(vp));
    k = vp.size();
 
    for (int i = 1; i < k; i ++) {
        vector<int> an(k + 2);
        for (int j = i - 1; 0 <= j; j --) {
            wz[j][i] = an[j] = gt(vp[j], vp[i], z);
            for (int l = j + 1; l < i; l ++)
                wz[j][i] = sb(wz[j][i], ml(wz[j][l], an[l], z), z);
        }
    }
 
    dp[0][1] = 1;
 
    for (int i = 1; i < k; i ++)
        for (int j = 0; j < i; j ++)
            for (int l = 2; l <= t + 2; l ++)
                dp[i][l] = ad(dp[i][l], ml(dp[j][l - 1], wz[j][i], z), z);
 
    ll r = 0;
 
    for (int i = 1; i <= t + 2; i ++)
        r = ad(r, dp[k - 1][i], z);
 
    // cout << ps.size() << '\n';
    cout << r << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1504 KB Output is correct
2 Incorrect 8 ms 1596 KB Output isn't correct
3 Incorrect 11 ms 1580 KB Output isn't correct
4 Incorrect 59 ms 1584 KB Output isn't correct
5 Correct 103 ms 1588 KB Output is correct
6 Correct 39 ms 1500 KB Output is correct
7 Incorrect 72 ms 1584 KB Output isn't correct
8 Incorrect 32 ms 1500 KB Output isn't correct
9 Incorrect 88 ms 1504 KB Output isn't correct
10 Incorrect 98 ms 1504 KB Output isn't correct
11 Incorrect 76 ms 1588 KB Output isn't correct
12 Correct 108 ms 1756 KB Output is correct
13 Incorrect 42 ms 1504 KB Output isn't correct
14 Correct 84 ms 1504 KB Output is correct
15 Correct 112 ms 1500 KB Output is correct
16 Incorrect 117 ms 1500 KB Output isn't correct
17 Incorrect 98 ms 1580 KB Output isn't correct
18 Correct 119 ms 1500 KB Output is correct
19 Correct 118 ms 1500 KB Output is correct
20 Correct 117 ms 1584 KB Output is correct