Submission #72755109
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using LL = long long;
#define fi first
#define se second
constexpr int MAXN = 3e4 + 5, M = 9, INF = 1e9;
int n, m, c[MAXN], dp[MAXN], pre[MAXN], a[MAXN][M], rev[MAXN][M];
inline void chmax(int &x, int y) { if (x < y) x = y; }
inline int calc(int p, int q) {
int ret = 0;
for (int i = 1; i <= m; ++i) {
for (int j = 1; j <= m; ++j) if (rev[p][i] < rev[p][j] && rev[q][i] > rev[q][j]) ++ret;
}
return ret;
}
int main() {
IOS;
cin >> n >> m;
int N = m * (m - 1) / 2;
iota(rev[0] + 1, rev[0] + 1 + m, 0);
for (int i = 1; i <= n; ++i) {
cin >> c[i];
for (int j = 0; j < m; ++j) cin >> a[i][j], rev[i][a[i][j]] = j;
dp[i] = -INF;
if (i > N) dp[i] = pre[i - 1 - N] + c[i];
for (int j = i - 1; j >= i - N && j >= 0; --j) if (calc(i, j) <= i - j) chmax(dp[i], dp[j] + c[i]);
pre[i] = dp[i];
chmax(pre[i], pre[i - 1]);
}
// cerr << calc(0, 1) << '\n';
cout << pre[n] << '\n';
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | A - Swapping Game |
| User | EnderLwz |
| Language | C++23 (GCC 15.2.0) |
| Score | 600 |
| Code Size | 1060 Byte |
| Status | AC |
| Exec Time | 87 ms |
| Memory | 6268 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 600 / 600 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt, example2.txt, example3.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, example0.txt, example1.txt, example2.txt, example3.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 1 ms | 3656 KiB |
| 001.txt | AC | 3 ms | 6140 KiB |
| 002.txt | AC | 4 ms | 6108 KiB |
| 003.txt | AC | 5 ms | 6072 KiB |
| 004.txt | AC | 8 ms | 6044 KiB |
| 005.txt | AC | 27 ms | 6140 KiB |
| 006.txt | AC | 59 ms | 6048 KiB |
| 007.txt | AC | 86 ms | 6072 KiB |
| 008.txt | AC | 15 ms | 6168 KiB |
| 009.txt | AC | 40 ms | 6040 KiB |
| 010.txt | AC | 87 ms | 6268 KiB |
| 011.txt | AC | 86 ms | 6072 KiB |
| 012.txt | AC | 59 ms | 6036 KiB |
| 013.txt | AC | 86 ms | 6268 KiB |
| 014.txt | AC | 84 ms | 5960 KiB |
| 015.txt | AC | 75 ms | 6072 KiB |
| 016.txt | AC | 79 ms | 6048 KiB |
| 017.txt | AC | 82 ms | 6112 KiB |
| 018.txt | AC | 84 ms | 6044 KiB |
| 019.txt | AC | 85 ms | 6044 KiB |
| 020.txt | AC | 79 ms | 6268 KiB |
| 021.txt | AC | 79 ms | 6108 KiB |
| 022.txt | AC | 83 ms | 6088 KiB |
| 023.txt | AC | 82 ms | 6072 KiB |
| 024.txt | AC | 84 ms | 6024 KiB |
| 025.txt | AC | 79 ms | 6216 KiB |
| 026.txt | AC | 80 ms | 6044 KiB |
| 027.txt | AC | 83 ms | 6144 KiB |
| 028.txt | AC | 85 ms | 6044 KiB |
| 029.txt | AC | 86 ms | 6048 KiB |
| 030.txt | AC | 79 ms | 6024 KiB |
| 031.txt | AC | 82 ms | 6108 KiB |
| 032.txt | AC | 85 ms | 6024 KiB |
| 033.txt | AC | 85 ms | 6216 KiB |
| 034.txt | AC | 72 ms | 6048 KiB |
| 035.txt | AC | 77 ms | 6048 KiB |
| 036.txt | AC | 72 ms | 6036 KiB |
| example0.txt | AC | 1 ms | 3608 KiB |
| example1.txt | AC | 1 ms | 3612 KiB |
| example2.txt | AC | 1 ms | 3592 KiB |
| example3.txt | AC | 1 ms | 3708 KiB |