#include <cstdio> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define FORD(i,a,b) for(int i=(b)-1;i>=(a);--i) #define REP(i,n) FOR(i,0,n) #define REPD(i,n) FORD(i,0,n) #define INT(x) int x; scanf("%d", &x) typedef long long LL; int r[10000000], x[10000000], y[10000001]; int main() { INT(n); INT(m); INT(p); REP(i,n) { if (!i) REP(j,m) r[j] = m - j; else REP(j,m) r[j] = (LL(m - j) * ((x[0] + p - x[m - j]) % p) % p + p - y[j + 1]) % p; x[m - 1] = y[m - 1] = r[m - 1]; REPD(j,m-1) x[j] = (r[j] + x[j + 1]) % p; REPD(j,m-1) y[j] = (x[j] + y[j + 1]) % p; } printf("%d\n", x[0]); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <cstdio> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define FORD(i,a,b) for(int i=(b)-1;i>=(a);--i) #define REP(i,n) FOR(i,0,n) #define REPD(i,n) FORD(i,0,n) #define INT(x) int x; scanf("%d", &x) typedef long long LL; int r[10000000], x[10000000], y[10000001]; int main() { INT(n); INT(m); INT(p); REP(i,n) { if (!i) REP(j,m) r[j] = m - j; else REP(j,m) r[j] = (LL(m - j) * ((x[0] + p - x[m - j]) % p) % p + p - y[j + 1]) % p; x[m - 1] = y[m - 1] = r[m - 1]; REPD(j,m-1) x[j] = (r[j] + x[j + 1]) % p; REPD(j,m-1) y[j] = (x[j] + y[j + 1]) % p; } printf("%d\n", x[0]); } |