QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#87239#1895. Moving CellsBeevo#WA 2ms3468kbC++231.1kb2023-03-12 02:06:022023-03-12 02:06:04

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-12 02:06:04]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 3468kb
  • [2023-03-12 02:06:02]
  • Submitted

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 <= n; 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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3396kb

input:

9 3
1 2
4 5
7 9

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3384kb

input:

1 5
1 1
1 1
1 1
1 1
1 1

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3364kb

input:

9 1
5 7

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 2ms
memory: 3468kb

input:

10 5
1 1
4 4
4 4
5 5
3 3

output:

5

result:

ok 1 number(s): "5"

Test #5:

score: -100
Wrong Answer
time: 2ms
memory: 3372kb

input:

7 6
5 7
3 5
4 5
1 3
5 7
5 7

output:

0

result:

wrong answer 1st numbers differ - expected: '2', found: '0'