QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#412107 | #3166. Hopscotch | ivan_len# | RE | 3ms | 3880kb | C++20 | 1.2kb | 2024-05-16 08:19:58 | 2024-05-16 08:19:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
#define PB push_back
#define MP make_pair
#define A first
#define B second
#define SZ(x) int(x.size())
#define FR(i, a, b) for (int i = (a); i < (b); ++i)
#define FOR(i, n) FR(i, 0, n)
const int M = 1000000007;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
int n, k;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
vector<vector<vi>> dp(n + 5);
FOR(i, n) {
FOR(j, n) {
int x;
cin >> x;
dp[x].PB({i, j, 0});
}
}
int mn = 1 << 30;
FR(i, 2, k + 1) {
int s = SZ(dp[i - 1]);
int t = SZ(dp[i]);
FOR(j, t) {
dp[i][j][2] = 1 << 30;
FOR(l, s) {
dp[i][j][2] = min(dp[i][j][2], dp[i - 1][l][2] + abs(dp[i - 1][l][0] - dp[i][j][0]) + abs(dp[i - 1][l][1] - dp[i][j][1]));
}
if (i == k) mn = min(mn, dp[i][j][2]);
}
}
if (mn == (1 << 30)) cout << "-1\n";
else cout << mn << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3880kb
input:
10 5 5 1 3 4 2 4 2 1 2 1 4 5 3 4 1 5 3 1 1 4 4 2 4 1 5 4 5 2 4 1 5 2 1 5 5 3 5 2 3 2 5 5 2 3 2 3 1 5 5 5 3 4 2 4 2 2 4 4 2 3 1 5 1 1 2 5 4 1 5 3 2 2 4 1 2 5 1 4 3 5 5 3 2 1 4 3 5 2 3 1 3 4 2 5 2 5 3 4 4 2
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
10 5 5 1 5 4 1 2 2 4 5 2 4 2 1 4 1 1 1 5 2 5 2 2 4 4 4 2 4 5 5 4 2 4 4 5 5 5 2 5 5 2 2 2 4 4 4 5 4 2 4 4 5 2 5 5 4 1 2 4 4 4 4 2 1 2 4 4 1 2 4 5 1 2 1 1 2 4 4 1 4 5 2 1 2 5 5 4 5 2 1 1 1 1 2 4 5 5 5 5 5 5
output:
-1
result:
ok single line: '-1'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
50 10 1 5 5 4 3 6 9 6 4 4 2 8 2 9 4 4 5 2 8 6 9 4 3 9 9 3 4 9 3 9 2 9 8 8 5 9 9 6 9 7 6 7 9 3 7 8 9 3 8 2 6 7 7 3 8 6 3 7 2 3 5 4 8 2 5 3 3 5 3 9 6 2 7 2 2 8 6 7 9 8 5 2 4 9 8 6 8 8 4 3 8 4 8 5 4 5 4 8 3 4 6 8 4 9 2 6 5 9 7 7 2 3 9 8 5 3 2 4 2 3 9 6 7 4 9 4 2 2 2 4 7 4 2 2 8 6 9 3 9 2 2 9 2 9 4 4 8 ...
output:
98
result:
ok single line: '98'
Test #4:
score: 0
Accepted
time: 3ms
memory: 3880kb
input:
50 4 1 3 2 3 3 3 2 2 3 3 2 3 2 2 3 3 3 2 3 3 2 2 3 2 3 3 3 3 3 2 2 2 3 2 2 3 2 2 2 2 2 2 2 3 3 2 3 2 2 3 3 3 2 2 3 3 2 2 3 2 2 3 3 3 3 2 3 3 2 3 2 2 2 3 2 2 3 3 2 3 3 2 3 3 2 3 3 2 3 3 3 2 2 3 2 3 3 3 2 2 3 2 3 3 2 2 2 2 3 3 3 2 2 2 3 3 3 3 2 2 3 2 3 3 3 3 3 2 3 3 2 3 3 3 2 2 2 3 2 2 2 2 3 2 3 2 3 3...
output:
98
result:
ok single line: '98'
Test #5:
score: -100
Runtime Error
input:
50 2500 658 2195 1188 410 197 1347 17 1507 1003 329 217 85 1211 1208 2038 2407 662 800 590 796 40 519 697 750 1344 413 280 2360 2406 1838 1235 557 2455 2199 875 912 1511 1615 605 1272 422 88 1127 393 787 216 693 48 1193 399 1153 416 330 983 632 1692 1232 2355 1371 2409 768 1978 1693 1277 2307 684 20...