Submission #2538941
Source Code Expand
#include<bits/stdc++.h>
#define L long long
using namespace std;
int n,m,q,f[310][310],g[310][310],h[310][310],x[310][310],y[310][310],c[310][310];
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
int i,j,k;
scanf("%d%d%d",&n,&m,&q);
//n++;
for(i=0;i<=n;i++)
for(c[i][0]=1,j=1;j<=i;j++)
c[i][j]=(c[i-1][j]+c[i-1][j-1])%q;
f[0][m+1]=1;
x[0][m+1]=1;
for(i=0;i<=n;i++)
{
for(j=1;j<=m;j++)
for(k=0;k<i;k++)
f[i][j]=(f[i][j]+((L)g[k][j]*x[i-1-k][j]+(L)y[k][j+1]*f[i-1-k][j])%q*c[i-1][k])%q;
for(j=m;j>=1;j--)
g[i][j]=(g[i][j+1]+f[i][j+1])%q;
//for(j=1;j<=n;j++)
//h[i][j]=(h[i][j-1]+f[i][j])%q;
for(j=m;j>=1;j--)
x[i][j]=(x[i][j+1]+f[i][j])%q;
for(j=m;j>=1;j--)
y[i][j]=(y[i][j+1]+g[i][j])%q;
//for(j=1;j<=m;j++)
//cout<<i<<" "<<j<<" "<<f[i][j]<<" "<<g[i][j]<<" "<<h[i][j]<<" "<<x[i][j]<<" "<<y[i][j]<<"!!\n";
}
/*for(i=m;i>=0;i--)
{
f[i][1]=1;
for(j=2;j<=n;j++)
for(k=1;k<j;k++)
f[i][j]=(f[i][j]+(L)g[i+1][k]*f[i][j-k]%q*c[j][k])%q;
for(j=1;j<=n;j++)
g[i][j]=(g[i+1][j]+f[i][j])%q;
}
cout<<f[0][1]<<" "<<f[0][2]<<" "<<g[1][1]<<" "<<g[1][2]<<" ";*/
printf("%d\n",x[n][1]);
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Sequence Growing Hard |
| User | fateice |
| Language | C++14 (GCC 5.4.1) |
| Score | 1200 |
| Code Size | 1338 Byte |
| Status | AC |
| Exec Time | 406 ms |
| Memory | 2048 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:10:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&n,&m,&q);
^
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 1200 / 1200 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | s1.txt, s2.txt, s3.txt |
| All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, s1.txt, s2.txt, s3.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01.txt | AC | 406 ms | 2048 KiB |
| 02.txt | AC | 356 ms | 2048 KiB |
| 03.txt | AC | 231 ms | 1664 KiB |
| 04.txt | AC | 2 ms | 256 KiB |
| 05.txt | AC | 377 ms | 2048 KiB |
| 06.txt | AC | 4 ms | 2048 KiB |
| 07.txt | AC | 2 ms | 256 KiB |
| 08.txt | AC | 382 ms | 2048 KiB |
| 09.txt | AC | 379 ms | 2048 KiB |
| 10.txt | AC | 221 ms | 1664 KiB |
| 11.txt | AC | 153 ms | 1664 KiB |
| 12.txt | AC | 2 ms | 256 KiB |
| 13.txt | AC | 1 ms | 256 KiB |
| 14.txt | AC | 406 ms | 2048 KiB |
| 15.txt | AC | 40 ms | 1920 KiB |
| 16.txt | AC | 270 ms | 1920 KiB |
| 17.txt | AC | 2 ms | 384 KiB |
| 18.txt | AC | 310 ms | 2048 KiB |
| 19.txt | AC | 393 ms | 2048 KiB |
| 20.txt | AC | 85 ms | 1664 KiB |
| 21.txt | AC | 5 ms | 2048 KiB |
| 22.txt | AC | 306 ms | 2048 KiB |
| 23.txt | AC | 354 ms | 1920 KiB |
| 24.txt | AC | 4 ms | 512 KiB |
| 25.txt | AC | 10 ms | 512 KiB |
| 26.txt | AC | 342 ms | 2048 KiB |
| 27.txt | AC | 6 ms | 512 KiB |
| 28.txt | AC | 70 ms | 2048 KiB |
| 29.txt | AC | 283 ms | 1920 KiB |
| 30.txt | AC | 10 ms | 768 KiB |
| 31.txt | AC | 342 ms | 1920 KiB |
| 32.txt | AC | 402 ms | 2048 KiB |
| s1.txt | AC | 1 ms | 256 KiB |
| s2.txt | AC | 2 ms | 256 KiB |
| s3.txt | AC | 50 ms | 1152 KiB |