Submission #72755352
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const int N = 30005;
const int INF = 0x3f3f3f3f;
int p[N][10];
int c[N];
ll f[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, l;
cin >> n >> l;
for (int i = 0; i < l; i++) p[0][i] = i + 1;
for (int i = 1; i <= n; i++) {
cin >> c[i];
for (int j = 0; j < l; j++) cin >> p[i][j];
}
for (int i = 1; i <= n; i++) f[i] = -1;
ll mx = -1;
for (int i = 1; i <= n; i++) {
int pos = i - max(1, l * (l - 1) / 2);
if (pos >= 0) mx = max(mx, f[pos]);
ll w = mx;
for (int j = max(0, i - l * (l - 1) / 2 + 1); j < i; j++) {
if (f[j] == -1) continue;
vector<int> pos(10, 0);
for (int x = 0; x < l; x++) pos[p[j][x]] = x;
int d = 0;
for (int x = 0; x < l; x++) {
for (int y = 0; y < x; y++) {
if (pos[p[i][y]] > pos[p[i][x]]) d++;
}
if (d > i - j) break;
}
if (d <= i - j) {
if (w == -1 || f[j] > w) w = f[j];
}
}
if (w != -1) f[i] = w + c[i];
}
ll ans = 0;
for (int i = 0; i <= n; i++) ans = max(ans, f[i]);
cout << ans << "\n";
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | A - Swapping Game |
| User | jiangxinyang2012 |
| Language | C++23 (GCC 15.2.0) |
| Score | 600 |
| Code Size | 1398 Byte |
| Status | AC |
| Exec Time | 44 ms |
| Memory | 5236 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 | 3700 KiB |
| 001.txt | AC | 3 ms | 5088 KiB |
| 002.txt | AC | 3 ms | 5024 KiB |
| 003.txt | AC | 5 ms | 5048 KiB |
| 004.txt | AC | 8 ms | 5088 KiB |
| 005.txt | AC | 18 ms | 5148 KiB |
| 006.txt | AC | 33 ms | 5044 KiB |
| 007.txt | AC | 44 ms | 4944 KiB |
| 008.txt | AC | 12 ms | 5160 KiB |
| 009.txt | AC | 25 ms | 5088 KiB |
| 010.txt | AC | 44 ms | 5016 KiB |
| 011.txt | AC | 44 ms | 5148 KiB |
| 012.txt | AC | 33 ms | 5056 KiB |
| 013.txt | AC | 44 ms | 5000 KiB |
| 014.txt | AC | 43 ms | 5060 KiB |
| 015.txt | AC | 40 ms | 5056 KiB |
| 016.txt | AC | 41 ms | 5056 KiB |
| 017.txt | AC | 42 ms | 5048 KiB |
| 018.txt | AC | 44 ms | 5092 KiB |
| 019.txt | AC | 44 ms | 5024 KiB |
| 020.txt | AC | 43 ms | 5060 KiB |
| 021.txt | AC | 41 ms | 5076 KiB |
| 022.txt | AC | 42 ms | 5056 KiB |
| 023.txt | AC | 44 ms | 5092 KiB |
| 024.txt | AC | 44 ms | 5184 KiB |
| 025.txt | AC | 40 ms | 5236 KiB |
| 026.txt | AC | 40 ms | 5236 KiB |
| 027.txt | AC | 42 ms | 5048 KiB |
| 028.txt | AC | 44 ms | 5024 KiB |
| 029.txt | AC | 44 ms | 5092 KiB |
| 030.txt | AC | 43 ms | 5060 KiB |
| 031.txt | AC | 44 ms | 4976 KiB |
| 032.txt | AC | 44 ms | 5088 KiB |
| 033.txt | AC | 44 ms | 5188 KiB |
| 034.txt | AC | 40 ms | 5024 KiB |
| 035.txt | AC | 41 ms | 5148 KiB |
| 036.txt | AC | 40 ms | 5092 KiB |
| example0.txt | AC | 1 ms | 3464 KiB |
| example1.txt | AC | 1 ms | 3488 KiB |
| example2.txt | AC | 1 ms | 3700 KiB |
| example3.txt | AC | 1 ms | 3540 KiB |