QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#87238 | #1895. Moving Cells | Beevo# | RE | 0ms | 3472kb | C++23 | 1.1kb | 2023-03-12 02:02:45 | 2023-03-12 02:02:47 |
Judging History
answer
#include <bits/stdc++.h>
#define el '\n'
typedef long long ll;
typedef long double ld;
#define Beevo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
void testCase() {
int n, m;
cin >> n >> m;
int u[m + 1], d[m + 1];
for (int j = 1; j <= m; j++)
cin >> u[j] >> d[j];
ll dp[n + 1][m + 2];
memset(dp, '?', sizeof dp);
for (int i = 1; i <= m; i++)
dp[i][1] = 0;
multiset<ll> cur, rem[n + 1];
for (int j = 1; j <= m; j++) {
for (int i = 1; i + d[j] - u[j] <= n; i++) {
cur.insert(dp[i][j] + abs(i - u[j]));
rem[i + d[j] - u[j]].insert(dp[i][j] + abs(i - u[j]));
dp[i][j + 1] = *cur.begin();
while (rem[i].size())
cur.erase(cur.find(*rem[i].begin())), rem[i].erase(rem[i].begin());
}
}
ll mn = dp[1][m + 1];
for (int i = 2; i <= n; i++)
mn = min(mn, dp[i][m + 1]);
cout << mn;
}
signed main() {
Beevo
int t = 1;
// cin >> t;
while (t--)
testCase();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3472kb
input:
9 3 1 2 4 5 7 9
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: -100
Runtime Error
input:
1 5 1 1 1 1 1 1 1 1 1 1