# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
48811 |
2018-05-19T03:37:18 Z |
qkxwsm |
Tents (JOI18_tents) |
C++17 |
|
2000 ms |
81236 KB |
/*
PROG: joi_tents
LANG: C++11
_____
.' '.
/ 0 0 \
| ^ |
| \ / |
\ '---' /
'._____.'
*/
#include <bits/stdc++.h>
using namespace std;
template<class T>
void readi(T &x)
{
T input = 0;
bool negative = false;
char c = ' ';
while (c < '-')
{
c = getchar();
}
if (c == '-')
{
negative = true;
c = getchar();
}
while (c >= '0')
{
input = input * 10 + (c - '0');
c = getchar();
}
if (negative)
{
input = -input;
}
x = input;
}
template<class T>
void printi(T output)
{
if (output == 0)
{
putchar('0');
return;
}
if (output < 0)
{
putchar('-');
output = -output;
}
int aout[20];
int ilen = 0;
while(output)
{
aout[ilen] = ((output % 10));
output /= 10;
ilen++;
}
for (int i = ilen - 1; i >= 0; i--)
{
putchar(aout[i] + '0');
}
return;
}
template<class T>
void ckmin(T &a, T b)
{
a = min(a, b);
}
template<class T>
void ckmax(T &a, T b)
{
a = max(a, b);
}
long long randomize(long long mod)
{
return ((1ll << 30) * rand() + (1ll << 15) * rand() + rand()) % mod;
}
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-20;
#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll
#define MAXN 3013
long long normalize(long long x, long long mod = INF)
{
return (((x % mod) + mod) % mod);
}
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int N, M;
ll dp[2][MAXN][MAXN];
ll ans;
ll choose2(ll x)
{
return (x * (x - 1) / 2) % INF;
}
void mark(int x, int y, ll val)
{
if (x < 0 || x > M || y < 0 || y > M)
{
return;
}
dp[1][x][y] += val;
dp[1][x][y] %= INF;
return;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
srand(time(0));
// cout << fixed << setprecision(12);
// cerr << fixed << setprecision(12);
if (fopen("joi_tents.in", "r"))
{
freopen ("joi_tents.in", "r", stdin);
freopen ("joi_tents.out", "w", stdout);
}
cin >> N >> M;
if (N < M)
{
swap(N, M);
}
//# blank, #N-only
dp[0][M][0] = 1;
for (int i = 0; i < N; i++)
{
//add nothing
//add only one N
//add only one S to an N
//add only one S
//add only one E
//add only one W
//add EW
for (int j = 0; j <= M; j++)
{
for (int k = 0; k <= M; k++)
{
ll val = dp[0][j][k];
mark(j, k, val);
mark(j - 1, k + 1, val * j);
mark(j, k - 1, val * k);
mark(j - 1, k, 3ll * val * j);
mark(j - 2, k, val * choose2(j));
}
}
for (int j = 0; j <= M; j++)
{
for (int k = 0; k <= M; k++)
{
dp[0][j][k] = dp[1][j][k];
dp[1][j][k] = 0;
}
}
}
ans += (INF - 1);
for (int i = 0; i <= M; i++)
{
for (int j = 0; j <= M; j++)
{
ans += dp[0][i][j];
ans %= INF;
}
}
cout << ans << '\n';
// cerr << "time elapsed = " << (clock() / (CLOCKS_PER_SEC / 1000)) << " ms" << endl;
return 0;
}
Compilation message
tents.cpp: In function 'int32_t main()':
tents.cpp:141:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen ("joi_tents.in", "r", stdin);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
tents.cpp:142:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen ("joi_tents.out", "w", stdout);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
744 KB |
Output is correct |
4 |
Correct |
2 ms |
744 KB |
Output is correct |
5 |
Correct |
32 ms |
1328 KB |
Output is correct |
6 |
Correct |
50 ms |
1500 KB |
Output is correct |
7 |
Correct |
58 ms |
1612 KB |
Output is correct |
8 |
Correct |
24 ms |
1612 KB |
Output is correct |
9 |
Correct |
2 ms |
1612 KB |
Output is correct |
10 |
Correct |
150 ms |
2196 KB |
Output is correct |
11 |
Correct |
4 ms |
2196 KB |
Output is correct |
12 |
Correct |
862 ms |
4724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
744 KB |
Output is correct |
4 |
Correct |
2 ms |
744 KB |
Output is correct |
5 |
Correct |
32 ms |
1328 KB |
Output is correct |
6 |
Correct |
50 ms |
1500 KB |
Output is correct |
7 |
Correct |
58 ms |
1612 KB |
Output is correct |
8 |
Correct |
24 ms |
1612 KB |
Output is correct |
9 |
Correct |
2 ms |
1612 KB |
Output is correct |
10 |
Correct |
150 ms |
2196 KB |
Output is correct |
11 |
Correct |
4 ms |
2196 KB |
Output is correct |
12 |
Correct |
862 ms |
4724 KB |
Output is correct |
13 |
Correct |
3 ms |
4724 KB |
Output is correct |
14 |
Correct |
3 ms |
4724 KB |
Output is correct |
15 |
Execution timed out |
2066 ms |
81236 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |