Submission #1793784
Source Code Expand
#include <bits/stdc++.h> #define mk make_pair #define ll long long using namespace std; const int N = 400; const int mod = 1e9 + 7; int n, ans, g[N][N], f[N][N], s[N][N]; int a[N], b[N], pa[N], pb[N], cnt[N][N], ss[N], cnt_; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; pa[a[i]] = i; } for (int i = 1; i <= n; i++) { cin >> b[i]; pb[b[i]] = i; } for (int i = 1; i <= n; i++) { ss[a[i]]++; if (ss[a[i]] == 1) cnt_++; for (int j = 1; j <= n; j++) { ss[b[j]]++; if (ss[b[j]] == 1) cnt_++; cnt[i][j] = cnt_; } for (int j = 1; j <= n; j++) { ss[b[j]]--; if (ss[b[j]] == 0) cnt_--; } } for (int i = 1; i <= n + 1; i++) for (int j = 1; j <= n + 1; j++) s[i][j] = 1; for (int i = 1; i <= n / 3; i++) { for (int j = 1; j <= n; j++) { for (int k = 1; k <= n; k++) { f[j][k] = 0; if (pa[b[k]] <= j) continue; if (pb[a[j]] <= k) continue; f[j][k] = (ll)(n - cnt[j][k] - (i - 1) * 3) * s[j + 1][k + 1] % mod; } } for (int j = 0; j <= n; j++) s[j][n + 1] = s[n + 1][j] = s[n + 1][n + 1] = 0; for (int j = n; j >= 1; j--) { for (int k = n; k >= 1; k--) { s[j][k] = f[j][k]; (s[j][k] += (s[j + 1][k] + s[j][k + 1]) % mod) %= mod; } } } for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) (ans += f[i][j]) %= mod; g[0][0] = 1; for (int i = 0; i <= n / 3; i++) { for (int j = 0; j <= n; j++) { if (g[i][j] == 0) continue; if (i * 3 > j) (g[i][j + 1] += (ll)g[i][j] * (3 * i - j) % mod) %= mod; (g[i + 1][j + 1] += g[i][j]) %= mod; } } cout << (ll)ans * g[n / 3][n] % mod << endl; }
Submission Info
Submission Time | |
---|---|
Task | F - Three Gluttons |
User | liumh8 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1682 Byte |
Status | WA |
Exec Time | 270 ms |
Memory | 2432 KB |
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 1800 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 1 ms | 256 KB |
0_01.txt | AC | 1 ms | 256 KB |
0_02.txt | WA | 1 ms | 256 KB |
0_03.txt | AC | 1 ms | 256 KB |
0_04.txt | AC | 1 ms | 256 KB |
1_00.txt | AC | 228 ms | 2304 KB |
1_01.txt | AC | 237 ms | 2304 KB |
1_02.txt | AC | 237 ms | 2304 KB |
1_03.txt | WA | 238 ms | 2304 KB |
1_04.txt | WA | 238 ms | 2304 KB |
1_05.txt | AC | 237 ms | 2304 KB |
1_06.txt | AC | 239 ms | 2304 KB |
1_07.txt | WA | 245 ms | 2304 KB |
1_08.txt | WA | 264 ms | 2304 KB |
1_09.txt | WA | 263 ms | 2304 KB |
1_10.txt | WA | 265 ms | 2304 KB |
1_11.txt | WA | 258 ms | 2304 KB |
1_12.txt | WA | 246 ms | 2304 KB |
1_13.txt | WA | 270 ms | 2304 KB |
1_14.txt | WA | 265 ms | 2304 KB |
1_15.txt | WA | 269 ms | 2304 KB |
1_16.txt | WA | 250 ms | 2304 KB |
1_17.txt | WA | 249 ms | 2304 KB |
1_18.txt | WA | 243 ms | 2304 KB |
1_19.txt | WA | 243 ms | 2304 KB |
1_20.txt | WA | 238 ms | 2304 KB |
1_21.txt | WA | 249 ms | 2304 KB |
1_22.txt | WA | 249 ms | 2304 KB |
1_23.txt | WA | 249 ms | 2304 KB |
1_24.txt | WA | 254 ms | 2432 KB |
1_25.txt | WA | 258 ms | 2304 KB |
1_26.txt | WA | 241 ms | 2304 KB |
1_27.txt | WA | 252 ms | 2304 KB |
1_28.txt | WA | 252 ms | 2304 KB |
1_29.txt | WA | 258 ms | 2304 KB |
1_30.txt | WA | 246 ms | 2304 KB |
1_31.txt | WA | 241 ms | 2304 KB |