QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#404229 | #5697. 萨菲克斯·阿瑞 | chenxinyang2006 | 100 ✓ | 211ms | 6892kb | C++14 | 4.7kb | 2024-05-03 16:27:11 | 2024-05-03 16:27:13 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
template <int P>
class mod_int
{
using Z = mod_int;
private:
static int mo(int x) { return x < 0 ? x + P : x; }
public:
int x;
int val() const { return x; }
mod_int() : x(0) {}
template <class T>
mod_int(const T &x_) : x(x_ >= 0 && x_ < P ? static_cast<int>(x_) : mo(static_cast<int>(x_ % P))) {}
bool operator==(const Z &rhs) const { return x == rhs.x; }
bool operator!=(const Z &rhs) const { return x != rhs.x; }
Z operator-() const { return Z(x ? P - x : 0); }
Z pow(long long k) const
{
Z res = 1, t = *this;
while (k)
{
if (k & 1)
res *= t;
if (k >>= 1)
t *= t;
}
return res;
}
Z &operator++()
{
x < P - 1 ? ++x : x = 0;
return *this;
}
Z &operator--()
{
x ? --x : x = P - 1;
return *this;
}
Z operator++(int)
{
Z ret = x;
x < P - 1 ? ++x : x = 0;
return ret;
}
Z operator--(int)
{
Z ret = x;
x ? --x : x = P - 1;
return ret;
}
Z inv() const { return pow(P - 2); }
Z &operator+=(const Z &rhs)
{
(x += rhs.x) >= P && (x -= P);
return *this;
}
Z &operator-=(const Z &rhs)
{
(x -= rhs.x) < 0 && (x += P);
return *this;
}
Z operator-()
{
return -x;
}
Z &operator*=(const Z &rhs)
{
x = 1ULL * x * rhs.x % P;
return *this;
}
Z &operator/=(const Z &rhs) { return *this *= rhs.inv(); }
#define setO(T, o) \
friend T operator o(const Z &lhs, const Z &rhs) \
{ \
Z res = lhs; \
return res o## = rhs; \
}
setO(Z, +) setO(Z, -) setO(Z, *) setO(Z, /)
#undef setO
friend istream& operator>>(istream& is, mod_int& x)
{
long long tmp;
is >> tmp;
x = tmp;
return is;
}
friend ostream& operator<<(ostream& os, const mod_int& x)
{
os << x.val();
return os;
}
};
using Z = mod_int<mod>;
Z power(Z p,ll k){
Z ans = 1;
while(k){
if(k % 2 == 1) ans *= p;
p *= p;
k /= 2;
}
return ans;
}
int n,m;
int a[505];
Z fact[505],ifac[505];
Z f[505][505],dp[505][505],ed[505][505];//f[i][j] [1,i] 颜色用到了第 j 种.
int main(){
// freopen("ex_suffix3.in","r",stdin);
// freopen("test.out","w",stdout);
scanf("%d%d",&n,&m);
fact[0] = 1;
rep(i,1,n) fact[i] = fact[i - 1] * i;
ifac[n] = Z(1) / fact[n];
per(i,n - 1,0) ifac[i] = ifac[i + 1] * (i + 1);
rep(i,1,m) scanf("%d",&a[i]);
f[0][0] = 1;
rep(i,0,n){
rep(j,0,m){
dp[i][j] = f[i][j];
dp[i + 1][j] -= f[i][j];
}
// printf("i=%d\n",i);
rep(r,i,n){
if(r > i){
rep(j,0,m){
dp[r][j] += dp[r - 1][j];
ed[r][j] += ed[r - 1][j];
}
}
rep(j,0,m - 1){
dp[r + 1][j + 1] -= dp[r][j];
if(r + a[j + 1] <= n) dp[r + a[j + 1]][j + 1] += dp[r][j];
ed[r + 1][j + 1] += dp[r][j];
if(r + a[j + 1] <= n) ed[r + a[j + 1] + 1][j + 1] -= dp[r][j];
}
rep(j,0,m) f[r][j] += ed[r][j] * ifac[r - i];
/* printf("r=%d\n",r);
rep(j,0,m) printf("%d ",dp[r][j].val());
printf("\n");
rep(j,0,m) printf("%d ",ed[r][j].val());
printf("\n");*/
}
rep(r,i,n){
fill(dp[r],dp[r] + m + 1,0);
fill(ed[r],ed[r] + m + 1,0);
}
}
Z ans = 0;
rep(j,0,m) ans += f[n][j];
ans *= fact[n];
printf("%d\n",ans.val());
return 0;
}
详细
Test #1:
score: 5
Accepted
time: 0ms
memory: 6764kb
input:
6 3 2 3 4
output:
270
result:
ok 1 number(s): "270"
Test #2:
score: 5
Accepted
time: 2ms
memory: 6844kb
input:
10 7 1 3 4 2 8 4 4
output:
3395650
result:
ok 1 number(s): "3395650"
Test #3:
score: 5
Accepted
time: 2ms
memory: 6728kb
input:
10 7 5 2 4 7 2 9 9
output:
3521671
result:
ok 1 number(s): "3521671"
Test #4:
score: 5
Accepted
time: 4ms
memory: 6880kb
input:
490 2 397 150
output:
156076820
result:
ok 1 number(s): "156076820"
Test #5:
score: 5
Accepted
time: 0ms
memory: 6800kb
input:
499 3 365 104 84
output:
359276756
result:
ok 1 number(s): "359276756"
Test #6:
score: 5
Accepted
time: 93ms
memory: 6732kb
input:
495 181 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 495 ...
output:
367030087
result:
ok 1 number(s): "367030087"
Test #7:
score: 5
Accepted
time: 89ms
memory: 6700kb
input:
497 174 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 497 ...
output:
842700950
result:
ok 1 number(s): "842700950"
Test #8:
score: 5
Accepted
time: 2ms
memory: 6848kb
input:
47 37 24 47 34 37 32 25 42 33 27 47 47 23 35 46 41 27 2 0 2 3 0 2 4 0 2 1 2 1 4 1 3 44 44 35 25 24 26
output:
997241548
result:
ok 1 number(s): "997241548"
Test #9:
score: 5
Accepted
time: 0ms
memory: 6824kb
input:
50 33 44 32 32 31 40 38 37 35 29 29 30 25 40 45 36 46 36 4 1 2 1 2 3 5 5 5 4 3 4 2 5 3 29
output:
985463988
result:
ok 1 number(s): "985463988"
Test #10:
score: 5
Accepted
time: 2ms
memory: 6816kb
input:
45 35 40 28 26 34 3 4 1 4 2 1 4 2 4 4 4 3 0 1 1 37 22 33 23 30 39 39 30 39 44 31 29 38 44 39 23
output:
246027250
result:
ok 1 number(s): "246027250"
Test #11:
score: 5
Accepted
time: 12ms
memory: 6820kb
input:
192 149 123 184 177 147 156 148 141 158 185 172 100 150 134 157 156 127 140 128 130 156 139 130 105 172 162 119 122 174 166 189 107 189 104 172 168 163 99 100 113 188 176 157 139 167 166 185 143 105 148 130 187 115 145 163 140 186 145 139 185 166 161 178 185 124 153 182 191 174 136 133 170 106 154 1...
output:
18950292
result:
ok 1 number(s): "18950292"
Test #12:
score: 5
Accepted
time: 15ms
memory: 6892kb
input:
199 145 176 134 152 179 103 162 197 126 112 100 173 106 177 165 173 148 189 180 157 175 132 105 180 190 190 120 152 130 196 193 147 194 121 159 118 145 149 149 145 171 171 194 151 193 187 107 132 189 185 146 139 130 179 155 180 171 157 104 171 101 119 189 120 165 124 136 163 150 196 195 161 187 128 ...
output:
211123272
result:
ok 1 number(s): "211123272"
Test #13:
score: 5
Accepted
time: 16ms
memory: 6736kb
input:
198 153 124 132 193 111 184 197 150 163 195 169 99 162 112 153 169 165 183 175 136 192 161 171 180 12 19 2 17 9 11 18 0 12 17 4 2 12 9 7 109 181 1 13 7 16 9 5 5 12 12 16 6 10 6 15 5 102 113 101 126 157 177 189 191 134 124 145 126 170 144 122 192 110 161 183 196 167 127 161 150 188 188 111 158 194 18...
output:
921172591
result:
ok 1 number(s): "921172591"
Test #14:
score: 5
Accepted
time: 15ms
memory: 6696kb
input:
191 159 133 115 96 114 146 165 138 121 124 100 164 188 138 142 150 115 137 139 186 164 149 109 191 145 140 120 125 162 142 191 101 155 117 150 182 184 186 137 97 120 173 177 120 100 168 182 110 115 174 96 150 162 127 133 181 155 176 188 183 167 125 163 172 125 124 105 149 172 163 179 119 149 147 106...
output:
174115008
result:
ok 1 number(s): "174115008"
Test #15:
score: 5
Accepted
time: 207ms
memory: 6828kb
input:
486 391 416 380 330 466 464 404 405 399 345 362 440 413 461 469 442 250 379 281 333 376 417 453 470 450 353 324 427 323 345 293 378 373 470 328 420 408 374 373 248 470 286 328 457 276 444 474 466 328 322 456 435 420 12 26 25 16 35 35 35 5 42 3 23 15 7 17 21 479 381 401 289 463 339 289 374 332 275 33...
output:
61471107
result:
ok 1 number(s): "61471107"
Test #16:
score: 5
Accepted
time: 199ms
memory: 6688kb
input:
482 370 455 359 363 398 476 318 462 466 476 41 7 1 5 6 28 35 16 35 12 19 31 16 37 11 261 312 473 281 269 334 378 461 453 246 266 430 470 281 407 251 280 268 334 344 254 437 328 316 287 314 357 423 466 341 360 299 465 297 450 351 261 329 408 481 340 433 254 265 395 282 383 383 295 455 375 398 328 309...
output:
656550309
result:
ok 1 number(s): "656550309"
Test #17:
score: 5
Accepted
time: 189ms
memory: 6820kb
input:
486 363 344 293 362 446 364 332 289 413 249 462 261 401 461 253 295 439 358 395 457 269 457 321 366 332 282 384 322 243 282 295 252 448 389 483 486 398 261 435 443 351 331 432 317 442 354 244 305 293 386 443 316 371 329 349 360 364 363 442 411 450 306 458 444 372 384 382 430 323 348 352 378 262 321 ...
output:
819792353
result:
ok 1 number(s): "819792353"
Test #18:
score: 5
Accepted
time: 192ms
memory: 6832kb
input:
481 357 242 301 426 437 334 292 366 256 342 310 407 247 424 375 284 276 354 432 288 268 324 463 405 369 413 354 421 366 363 383 343 278 331 358 390 425 310 455 453 321 367 372 352 315 473 259 373 424 270 476 310 382 384 264 394 448 275 414 31 43 38 22 18 45 11 5 35 22 44 13 12 30 25 437 445 429 478 ...
output:
402601428
result:
ok 1 number(s): "402601428"
Test #19:
score: 5
Accepted
time: 211ms
memory: 6840kb
input:
480 383 364 323 402 326 358 360 242 400 448 401 284 265 383 270 426 267 355 375 308 416 334 246 280 344 374 242 324 306 332 454 263 435 287 326 359 267 290 445 369 255 392 381 298 383 428 280 417 419 308 364 415 314 28 2 25 5 37 12 4 31 39 39 32 36 47 9 39 334 404 285 433 424 434 298 404 300 423 344...
output:
873285991
result:
ok 1 number(s): "873285991"
Test #20:
score: 5
Accepted
time: 194ms
memory: 6808kb
input:
481 367 303 420 425 352 405 426 292 296 250 308 276 375 341 317 384 316 351 471 403 371 244 449 324 343 392 340 454 333 481 480 393 390 283 431 365 396 423 396 371 385 442 247 475 256 270 391 464 432 249 339 356 280 304 251 327 316 423 362 249 363 440 441 308 340 365 34 29 31 42 22 31 40 8 27 6 5 27...
output:
854884498
result:
ok 1 number(s): "854884498"
Extra Test:
score: 0
Extra Test Passed