QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#88331#1895. Moving CellsZuqaTL 29ms12780kbC++201.6kb2023-03-16 00:00:032023-03-16 00:00: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-16 00:00:04]
  • Judged
  • Verdict: TL
  • Time: 29ms
  • Memory: 12780kb
  • [2023-03-16 00:00:03]
  • Submitted

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define el '\n'
#define FIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
typedef unsigned long long ull;

template<typename T, typename X>
using hashTable = gp_hash_table<T, X>;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937_64 for long long
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());

void doWork()
{
    int n, m;
    cin >> n >> m;
    vector<int> len(m + 1);
    vector <pair<int, int>> v(m + 1);

    for(int i = 1; i <= m; i++)
        cin >> v[i].first >> v[i].second, len[i] = v[i].second - v[i].first;

    vector <vector<int>> dp(m + 1, vector<int>(n + 1));
    for(int i = 1; i <= m; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            dp[i][j] = 1e9 + 5;

            for(int k = max(1, j - len[i - 1]); k <= min(n, j + len[i]); k++)
                dp[i][j] = min(dp[i][j], abs(v[i].first - j) + dp[i - 1][k]);
        }
    }

//    for(int i = 1; i <= m; i++, cout << '\n')
//        for(int j = 1; j <= n; j++)
//            cout << dp[i][j] << ' ';
    cout << *min_element(dp[m].begin() + 1, dp[m].end());
}

signed main()
{
    FIO
    int T = 1;
//    cin >> T;
    for(int i = 1; i <= T; i++)
        doWork();
}

詳細信息

Test #1:

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

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: 3388kb

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: 2ms
memory: 3396kb

input:

9 1
5 7

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

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

output:

5

result:

ok 1 number(s): "5"

Test #5:

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

input:

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

output:

2

result:

ok 1 number(s): "2"

Test #6:

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

input:

7 10
1 7
1 5
1 6
1 5
1 7
1 5
1 7
1 7
1 6
1 5

output:

0

result:

ok 1 number(s): "0"

Test #7:

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

input:

6 6
1 1
6 6
1 1
6 6
1 1
6 6

output:

15

result:

ok 1 number(s): "15"

Test #8:

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

input:

7 9
1 3
5 6
1 2
5 6
1 2
6 7
1 3
4 6
2 3

output:

10

result:

ok 1 number(s): "10"

Test #9:

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

input:

5 5
3 5
1 2
1 5
1 3
1 5

output:

1

result:

ok 1 number(s): "1"

Test #10:

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

input:

10 7
1 10
7 7
1 1
2 7
9 9
6 6
1 9

output:

9

result:

ok 1 number(s): "9"

Test #11:

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

input:

5 8
1 4
1 3
3 4
1 3
1 2
2 4
1 3
1 3

output:

0

result:

ok 1 number(s): "0"

Test #12:

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

input:

10 10
1 9
2 7
2 7
2 8
2 7
2 6
2 7
2 8
2 7
1 8

output:

0

result:

ok 1 number(s): "0"

Test #13:

score: 0
Accepted
time: 22ms
memory: 11124kb

input:

9 99994
2 2
3 3
2 2
3 3
7 7
6 6
3 3
6 6
1 1
4 4
5 5
4 4
2 2
1 1
1 1
2 2
9 9
1 1
3 3
9 9
4 4
2 2
8 8
9 9
8 8
5 5
7 7
2 2
8 8
9 9
3 3
8 8
3 3
9 9
4 4
5 5
6 6
3 3
8 8
8 8
9 9
5 5
2 2
9 9
4 4
5 5
9 9
1 1
1 1
5 5
3 3
9 9
2 2
2 2
5 5
3 3
7 7
5 5
1 1
4 4
2 2
2 2
4 4
7 7
1 1
4 4
6 6
9 9
9 9
5 5
2 2
2 2
9 9
...

output:

222291

result:

ok 1 number(s): "222291"

Test #14:

score: 0
Accepted
time: 17ms
memory: 11156kb

input:

7 99994
1 2
5 7
5 7
4 6
2 3
4 5
1 2
1 2
5 6
4 5
1 3
5 7
5 6
3 4
2 4
2 3
4 6
4 6
2 4
3 5
2 4
5 7
3 5
5 6
4 6
1 2
4 6
4 6
3 5
1 3
4 6
1 2
2 3
3 4
1 3
2 3
5 7
5 6
4 6
4 5
5 7
2 3
4 6
4 5
3 4
3 5
2 4
3 5
3 5
3 4
1 3
1 2
4 5
5 6
5 7
4 6
4 5
2 4
1 3
3 4
4 5
4 5
2 4
5 6
3 5
5 7
5 7
1 3
2 3
1 2
1 3
4 5
3 4
...

output:

40532

result:

ok 1 number(s): "40532"

Test #15:

score: 0
Accepted
time: 23ms
memory: 9568kb

input:

5 100000
1 5
1 4
1 3
1 3
1 3
1 4
1 5
1 5
1 3
1 3
1 4
1 4
1 3
1 5
1 4
1 3
1 5
1 4
1 5
1 5
1 5
1 5
1 5
1 4
1 5
1 4
1 5
1 3
1 4
1 3
1 3
1 3
1 3
1 3
1 4
1 3
1 4
1 3
1 4
1 4
1 4
1 4
1 3
1 5
1 4
1 4
1 5
1 5
1 4
1 4
1 5
1 3
1 3
1 3
1 5
1 4
1 4
1 4
1 5
1 5
1 4
1 3
1 3
1 3
1 3
1 3
1 3
1 3
1 3
1 3
1 4
1 3
1 4...

output:

0

result:

ok 1 number(s): "0"

Test #16:

score: 0
Accepted
time: 25ms
memory: 11116kb

input:

7 99999
1 7
1 7
1 5
1 7
1 6
1 7
1 7
1 5
1 6
1 7
1 5
1 7
1 5
1 5
1 6
1 6
1 6
1 5
1 7
1 6
1 7
1 5
1 6
1 6
1 6
1 6
1 7
1 7
1 7
1 7
1 6
1 6
1 6
1 7
1 5
1 7
1 7
1 6
1 7
1 6
1 7
1 5
1 5
1 7
1 7
1 5
1 6
1 7
1 5
1 7
1 6
1 7
1 5
1 7
1 6
1 7
1 5
1 6
1 7
1 5
1 6
1 5
1 5
1 6
1 6
1 7
1 6
1 5
1 6
1 6
1 7
1 5
1 6
...

output:

0

result:

ok 1 number(s): "0"

Test #17:

score: 0
Accepted
time: 23ms
memory: 11100kb

input:

9 99998
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
9 9
1 1
...

output:

399992

result:

ok 1 number(s): "399992"

Test #18:

score: 0
Accepted
time: 20ms
memory: 11204kb

input:

7 99998
1 3
5 6
1 3
4 6
1 2
4 6
2 4
5 7
2 3
5 7
1 2
5 6
2 4
4 6
1 3
6 7
2 4
4 6
2 3
5 7
2 3
4 6
2 4
5 6
2 3
6 7
2 4
4 6
1 3
5 6
1 3
5 7
2 4
5 6
2 4
5 7
1 2
6 7
2 4
5 7
2 4
4 6
1 3
4 6
2 4
6 7
1 3
5 6
1 2
5 6
1 2
4 6
1 2
5 6
1 2
5 6
1 2
5 6
2 3
5 6
2 4
5 7
1 2
6 7
2 4
5 6
2 3
4 6
1 3
5 6
2 4
5 7
2 3
...

output:

100010

result:

ok 1 number(s): "100010"

Test #19:

score: 0
Accepted
time: 18ms
memory: 9588kb

input:

5 99993
1 4
1 4
1 4
1 4
2 5
2 4
1 3
1 3
2 5
1 5
2 4
1 3
3 5
1 5
2 4
1 3
2 4
1 3
3 5
2 4
3 5
3 5
1 4
1 4
3 5
1 3
3 5
2 4
3 5
2 4
2 4
1 3
3 5
2 5
1 3
3 5
1 4
2 5
1 3
2 4
3 5
1 3
1 5
2 4
1 3
2 4
1 4
1 5
3 5
1 5
1 4
1 5
2 5
1 3
3 5
2 4
3 5
2 5
2 4
1 5
2 5
1 3
2 4
1 4
1 4
3 5
3 5
1 4
2 4
1 3
3 5
1 3
3 5
...

output:

0

result:

ok 1 number(s): "0"

Test #20:

score: 0
Accepted
time: 11ms
memory: 9524kb

input:

5 99992
5 5
1 2
2 5
1 2
1 5
1 4
5 5
1 2
4 5
1 1
5 5
1 5
3 5
1 3
5 5
1 5
3 5
1 1
5 5
1 4
5 5
1 1
3 5
1 5
3 5
1 5
1 5
1 1
1 5
1 5
5 5
1 1
4 5
1 3
4 5
1 5
1 5
1 1
3 5
1 3
1 5
1 5
5 5
1 2
3 5
1 4
4 5
1 4
4 5
1 3
2 5
1 4
4 5
1 3
2 5
1 1
4 5
1 5
3 5
1 1
2 5
1 3
1 5
1 2
1 5
1 3
1 5
1 5
2 5
1 4
2 5
1 1
2 5
...

output:

50388

result:

ok 1 number(s): "50388"

Test #21:

score: 0
Accepted
time: 12ms
memory: 11128kb

input:

7 99990
1 5
1 1
1 6
7 7
1 7
4 4
1 7
7 7
1 6
5 5
1 4
5 5
1 4
2 2
1 6
5 5
1 6
4 4
1 6
7 7
1 4
4 4
1 6
3 3
1 4
7 7
1 5
1 1
1 6
2 2
1 5
5 5
1 4
7 7
1 4
3 3
1 6
3 3
1 6
2 2
1 6
1 1
1 7
6 6
1 5
7 7
1 6
4 4
1 7
5 5
1 7
5 5
1 5
6 6
1 7
5 5
1 6
6 6
1 7
5 5
1 5
6 6
1 4
6 6
1 7
6 6
1 7
1 1
1 6
4 4
1 5
1 1
1 7
...

output:

24625

result:

ok 1 number(s): "24625"

Test #22:

score: 0
Accepted
time: 18ms
memory: 9588kb

input:

5 99990
1 3
2 3
1 3
2 3
1 5
1 3
3 4
2 3
1 4
3 5
1 3
2 3
1 3
2 4
2 4
2 3
1 4
2 3
2 3
2 3
1 3
2 3
1 2
2 4
1 3
2 3
3 5
3 5
1 4
3 5
1 2
2 3
1 3
1 3
3 4
2 4
1 4
3 5
3 4
1 3
1 5
3 4
1 3
2 4
1 3
3 5
1 3
1 3
1 3
2 4
2 3
1 3
1 4
1 2
3 4
3 4
1 5
3 5
2 3
3 4
1 3
3 5
2 3
2 4
1 4
1 3
1 3
3 5
1 3
1 2
2 4
1 2
1 5
...

output:

4747

result:

ok 1 number(s): "4747"

Test #23:

score: 0
Accepted
time: 28ms
memory: 11148kb

input:

9 100000
2 7
5 8
2 5
3 5
2 6
4 8
4 8
2 9
1 5
2 5
4 7
5 7
1 4
3 7
2 6
3 6
2 4
5 7
1 5
1 5
3 5
2 6
5 7
1 5
2 5
4 7
4 6
1 3
1 5
2 5
4 6
4 8
3 5
3 7
2 4
2 7
4 7
1 3
5 8
2 6
2 5
1 5
1 8
3 5
2 5
2 6
2 6
1 3
5 8
1 9
2 5
4 6
4 6
5 9
1 4
5 7
2 7
1 5
3 5
4 8
3 5
3 7
2 6
2 8
2 4
4 7
3 7
5 7
4 8
3 6
2 7
5 9
2 6...

output:

8241

result:

ok 1 number(s): "8241"

Test #24:

score: 0
Accepted
time: 14ms
memory: 9592kb

input:

5 99992
1 5
1 5
1 5
1 5
1 5
1 3
1 5
1 5
1 5
1 5
1 5
1 5
1 5
1 5
1 5
1 5
1 5
1 5
1 5
1 5
1 3
1 5
1 5
1 5
1 5
1 3
1 5
1 5
1 5
1 5
1 3
1 5
1 5
1 5
1 5
1 3
1 5
1 5
1 5
1 5
1 4
1 5
1 5
1 5
1 5
1 4
1 5
1 5
1 5
1 5
1 3
1 5
1 5
1 5
1 5
1 4
1 5
1 5
1 5
1 5
1 3
1 5
1 5
1 5
1 5
1 4
1 5
1 5
1 5
1 5
1 4
1 5
1 5
...

output:

0

result:

ok 1 number(s): "0"

Test #25:

score: 0
Accepted
time: 18ms
memory: 11204kb

input:

8 99994
1 8
1 4
1 2
3 8
6 8
2 5
2 6
2 4
1 6
4 5
4 7
4 7
5 8
4 5
1 8
1 4
4 6
2 8
2 2
1 4
1 7
3 5
4 8
6 8
1 8
5 6
1 4
3 7
1 7
2 4
1 7
1 1
6 8
4 7
2 5
2 8
5 7
4 6
5 7
4 5
1 5
2 7
3 7
5 7
5 8
2 4
3 6
1 1
6 6
6 8
5 7
4 4
1 2
4 4
6 8
1 6
5 8
1 8
1 7
7 8
6 7
4 4
5 7
2 4
5 8
3 8
1 3
1 1
2 3
3 4
1 2
2 5
2 5
...

output:

40503

result:

ok 1 number(s): "40503"

Test #26:

score: 0
Accepted
time: 19ms
memory: 11060kb

input:

6 99994
4 6
1 3
1 6
5 5
4 6
4 6
1 3
2 5
1 4
3 4
2 4
2 6
1 3
1 5
4 6
2 2
3 4
1 6
1 2
2 6
1 3
2 2
3 4
5 5
2 4
4 5
4 4
1 4
1 2
3 4
3 4
3 4
1 4
4 6
5 6
5 6
3 4
5 6
3 4
2 2
5 6
2 3
1 2
3 6
5 6
1 4
3 6
1 4
3 4
2 3
2 3
1 2
1 6
4 6
2 5
2 2
1 2
1 4
1 1
3 6
1 3
2 4
2 5
1 3
1 3
2 5
4 5
1 5
2 2
2 4
4 4
1 3
2 6
...

output:

30352

result:

ok 1 number(s): "30352"

Test #27:

score: 0
Accepted
time: 29ms
memory: 12780kb

input:

10 99993
1 6
4 8
1 2
2 3
1 9
6 6
6 6
10 10
4 7
4 9
1 6
7 7
5 8
3 7
6 10
7 9
2 9
1 10
6 7
2 9
5 10
3 10
6 9
8 10
5 6
2 8
3 8
3 6
10 10
6 8
4 5
5 9
8 8
5 10
5 5
4 9
4 8
2 6
4 9
1 9
3 4
3 8
7 9
6 9
2 8
4 6
3 10
4 5
6 7
5 6
6 7
7 10
6 10
5 7
8 9
1 3
5 8
3 9
1 9
2 5
4 5
5 5
6 7
8 9
2 8
2 8
4 6
1 6
4 7
5 ...

output:

50942

result:

ok 1 number(s): "50942"

Test #28:

score: 0
Accepted
time: 22ms
memory: 11116kb

input:

6 99995
5 5
2 5
1 2
4 4
1 1
2 5
1 4
1 4
2 5
1 4
6 6
1 3
3 3
1 6
1 4
2 4
3 4
1 1
4 6
2 6
2 6
1 4
6 6
3 4
1 5
2 5
2 3
1 2
4 6
4 4
4 6
6 6
1 1
6 6
2 3
2 4
1 4
4 4
2 5
1 6
3 5
2 4
3 4
2 6
3 4
3 6
1 6
3 5
6 6
3 6
4 5
3 5
4 6
2 3
4 5
2 4
4 6
1 3
2 6
3 5
4 5
3 3
2 6
2 5
4 6
2 5
2 4
4 6
4 6
4 5
4 5
4 6
2 6
...

output:

30670

result:

ok 1 number(s): "30670"

Test #29:

score: 0
Accepted
time: 7ms
memory: 7404kb

input:

99992 9
48870 48870
3581 3581
91178 91178
52403 52403
64445 64445
49071 49071
58388 58388
24849 24849
43489 43489

output:

145625

result:

ok 1 number(s): "145625"

Test #30:

score: 0
Accepted
time: 9ms
memory: 5924kb

input:

99992 5
30892 30899
83142 83149
94126 94133
81332 81336
15094 15098

output:

131267

result:

ok 1 number(s): "131267"

Test #31:

score: -100
Time Limit Exceeded

input:

99994 6
88361 90181
92219 93672
65330 66575
34960 36437
69529 71565
26109 27788

output:


result: