QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#699185#2955. Stable Tablenickbelov#AC ✓2ms4604kbC++203.8kb2024-11-02 03:32:552024-11-02 03:32:56

Judging History

你现在查看的是最新测评结果

  • [2024-11-02 03:32:56]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:4604kb
  • [2024-11-02 03:32:55]
  • 提交

answer

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

using namespace std;
using namespace __gnu_pbds;

template<typename T>
ostream_iterator<T> oit(const string &s = " "){ return ostream_iterator<T>(cout,s.c_str()); }
inline auto rep(int l, int r) { return views::iota(min(l, r), r); }
inline auto rep(int n) { return rep(0, n); }
inline auto rep1(int l, int r) { return rep(l, r + 1); }
inline auto rep1(int n) { return rep(1, n + 1); }
inline auto per(int l, int r) { return rep(l, r) | views::reverse; }
inline auto per(int n) { return per(0, n); }
inline auto per1(int l, int r) { return per(l, r + 1); }
inline auto per1(int n) { return per(1, n + 1); }
#define A(a) begin(a),end(a)
inline auto len = ranges::ssize;

struct chash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
template<typename T, typename U> using pb_map = gp_hash_table<T, U, chash>;
template<typename T> using pb_set = gp_hash_table<T, null_type, chash>;
#define K first
#define V second

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vii = vector<vector<int>>;
typedef vector<ll> vll;
using pll = pair<ll,ll>;
using pii = pair<int,int>;

constexpr ll NN = 2e5, M = 1000000007, L = 20;

ll f1[NN], f2[NN];
ll inv(ll a, ll b=M) { return 1 < a ? b - inv(b % a, a) * b / a : 1; } // inv a mod b
ll choose(ll n, ll k) { return f1[n] * f2[k] % M * f2[n - k] % M; } // n choose k

void run()
{
    int h, w;
    cin >> h >> w;

    vii a(h, vi(w));

    for (auto &x : a) for (auto &x : x) cin >> x;

    int f = 9999;
    vii adj(1e4), radj(1e4);
    vi top;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (i == 0 && top.size() < 2 && (top.empty() || top.back() != a[i][j])) top.push_back(a[i][j]);

            if (i == h - 1) {
                adj[a[i][j]].push_back(f);
                radj[f].push_back(a[i][j]);
            } else {
                adj[a[i][j]].push_back(a[i + 1][j]);
                radj[a[i + 1][j]].push_back(a[i][j]);
            }
        }
    }

    vi da(1e4, 1e9);

    queue<int> nodes;
    nodes.push(top[0]);
    da[top[0]] = 0;
    while (nodes.size()) {
        int u = nodes.front();
        nodes.pop();

        for (int v : adj[u]) {
            if (da[v] == 1e9) {
                da[v] = da[u] + 1;
                nodes.push(v);
            }
        }
    }

    if (top.size() == 1) {
        cout << da[f];
        return;
    }

    vi db(1e4, 1e9);
    nodes.push(top[1]);
    db[top[1]] = 0;
    while (nodes.size()) {
        int u = nodes.front();
        nodes.pop();

        for (int v : adj[u]) {
            if (db[v] == 1e9) {
                db[v] = db[u] + 1;
                nodes.push(v);
            }
        }
    }

    vi df(1e4, 1e9); nodes.push(f);
    df[f] = 0;
    while (nodes.size()) {
        int u = nodes.front();
        nodes.pop();

        for (int v : radj[u]) {
            if (df[v] == 1e9) {
                df[v] = df[u] + 1;
                nodes.push(v);
            }
        }
    }

    ll ans = 1e9;
    for (int i = 0; i < 1e4; i++) {
        ans = min(ans, (ll)da[i] + db[i] + df[i]);
    }

    cout << ans;
}

int main()
{
    //KING OF THE WORLD...... U.W.T.B
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    run();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3936kb

input:

7 8
3 3 3 3 10 10 10 10
2 14 3 7 7 10 4 11
2 14 3 1 1 10 4 11
2 14 8 8 8 8 4 11
9 14 5 5 5 5 4 13
9 14 12 12 12 12 4 13
9 6 6 6 6 6 6 13

output:

5

result:

ok single line: '5'

Test #2:

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

input:

8 8
1 1 1 1 1 1 1 1
2 3 3 4 5 6 6 7
2 2 3 4 5 6 7 7
2 3 3 3 6 6 6 7
2 2 3 8 8 8 6 7
9 2 9 10 10 11 11 12
9 9 9 9 10 11 12 12
13 9 14 14 10 10 15 15

output:

3

result:

ok single line: '3'

Test #3:

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

input:

10 10
1 1 1 1 1 1 1 1 1 1
1 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 2
3 4 5 6 7 8 9 10 11 2
12 13 5 6 7 7 7 7 2 2
14 15 5 6 6 6 6 7 16 16
14 15 15 15 6 16 16 16 16 16
14 14 14 15 16 16 17 16 18 19
15 15 15 15 20 20 20 20 18 19
20 20 20 20 20 21 21 21 21 19

output:

4

result:

ok single line: '4'

Test #4:

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

input:

10 8
20 20 20 20 16 16 16 16
18 19 1 3 3 21 17 2
18 19 1 4 4 21 17 2
18 19 1 5 5 21 17 2
18 19 6 6 6 6 17 2
18 7 7 7 7 7 7 2
18 8 8 8 8 8 8 8
9 9 9 9 9 9 11 11
14 14 9 9 9 9 12 12
15 15 10 10 10 10 13 13

output:

7

result:

ok single line: '7'

Test #5:

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

input:

10 5
4 4 4 2 2
4 4 4 8 8
15 4 1 1 8
3 4 9 9 9
3 6 6 6 6
3 13 13 12 12
3 10 10 12 12
3 14 14 7 7
11 11 11 7 7
5 5 5 7 7

output:

7

result:

ok single line: '7'

Test #6:

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

input:

10 5
4 4 4 2 2
4 4 4 8 8
15 4 1 1 8
3 4 9 9 9
3 4 6 6 6
3 13 13 12 12
3 10 10 12 12
3 14 14 7 7
11 11 11 7 7
5 5 5 7 7

output:

8

result:

ok single line: '8'

Test #7:

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

input:

10 10
1 1 1 1 1 1 1 1 1 1
2 2 3 1 1 1 1 1 4 4
2 2 5 6 7 1 1 8 9 9
2 2 10 11 12 13 14 8 9 9
15 15 16 17 18 13 14 14 19 19
20 20 16 21 22 23 23 23 24 24
25 26 21 21 27 28 28 29 30 30
31 32 21 33 34 34 35 36 37 38
39 40 21 41 41 42 42 43 43 43
44 40 45 46 47 48 49 50 51 43

output:

6

result:

ok single line: '6'

Test #8:

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

input:

50 50
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 ...

output:

100

result:

ok single line: '100'

Test #9:

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

input:

100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 ...

output:

200

result:

ok single line: '200'

Test #10:

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

input:

8 12
13 13 13 13 13 13 13 13 3 3 3 3
13 13 13 13 13 13 13 13 3 2 2 3
13 13 13 1 1 13 13 13 3 3 3 3
13 13 13 1 1 13 13 13 8 11 11 11
13 13 13 13 13 7 8 8 8 11 11 11
13 13 13 13 13 7 9 9 9 11 11 11
4 4 4 4 6 6 10 10 10 11 12 12
5 5 5 5 6 6 10 12 12 12 12 12

output:

5

result:

ok single line: '5'

Test #11:

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

input:

50 50
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 ...

output:

75

result:

ok single line: '75'

Test #12:

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

input:

11 11
3 3 3 3 3 2 2 2 2 2 2
3 5 3 14 3 2 8 2 2 2 6
3 5 3 14 14 2 2 7 2 6 6
13 5 5 14 14 2 7 7 9 10 10
13 5 15 15 14 2 7 1 1 1 1
12 12 15 15 14 2 2 2 2 2 1
12 15 15 15 15 1 1 2 2 16 1
12 12 4 20 20 1 19 1 1 1 1
12 12 4 20 20 1 19 1 18 18 17
11 12 4 4 20 1 19 1 18 18 17
11 11 11 4 4 1 1 1 18 18 17

output:

6

result:

ok single line: '6'

Test #13:

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

input:

25 25
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2
1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 4 4 4 5 6 7 7 8
1 1 1 1 1 1 1 9 1 1 1 1 1 1 1 10 10 4 4 4 11 6 7 8 8
1 1 1 1 1 1 1 1 1 1 1 1 1 1 10 10 12 13 14 4 15 8 8 8 8
1 1 16 1 1 1 1 1 1 1 17 1 1 18 10 10 12 12 12 19 19 8 8 8 8
1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

4

result:

ok single line: '4'

Test #14:

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

input:

100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 1 1 1 3 1 1 1 1 4 4 5 6 1 1 7 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 8 9 10 1 1 1 11 12 12 13 1 1...

output:

17

result:

ok single line: '17'

Test #15:

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

input:

10 10
1 1 1 1 1 1 1 1 1 2
3 4 4 1 5 5 6 1 7 8
9 4 10 10 10 11 11 1 12 13
9 14 10 15 15 16 17 18 18 19
20 14 21 15 22 23 24 25 18 26
14 14 27 27 22 28 29 30 18 31
14 32 27 33 28 28 29 34 34 31
14 27 27 35 36 37 37 38 39 40
41 27 42 42 43 44 38 38 45 40
46 47 42 42 42 48 49 38 50 51

output:

12

result:

ok single line: '12'

Test #16:

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

input:

20 20
1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
3 4 4 5 6 6 7 8 9 9 10 2 11 12 2 13 2 2 14 14
3 15 16 17 18 18 19 8 20 9 10 21 22 22 13 13 23 23 14 24
3 25 25 18 18 18 26 27 20 28 10 21 22 29 13 30 31 32 14 24
3 3 25 18 18 33 34 35 36 28 10 37 38 39 40 30 30 14 14 41
42 43 44 45 46 33 34 47 48 49 50 5...

output:

14

result:

ok single line: '14'

Test #17:

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

input:

8 10
1 1 1 1 1 2 2 2 2 2
21 24 1 1 5 5 6 6 7 8
3 4 1 1 9 9 6 6 17 18
3 4 1 1 10 10 6 6 17 18
22 25 1 1 1 1 6 6 19 20
23 26 11 12 13 14 15 16 19 20
23 26 11 12 13 27 27 16 19 20
23 26 11 12 13 28 28 16 19 20

output:

5

result:

ok single line: '5'

Test #18:

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

input:

12 11
8 8 8 8 8 8 8 8 11 11 11
14 14 8 10 10 10 10 8 2 8 11
14 8 8 8 10 8 8 8 2 8 11
14 8 10 8 10 8 11 8 8 8 11
14 14 10 10 10 6 11 11 11 11 11
5 14 14 10 6 6 6 6 11 6 11
5 5 14 14 14 6 6 11 11 6 6
5 13 13 13 17 17 6 6 6 6 1
5 3 16 17 17 6 6 1 1 1 1
7 3 4 4 4 4 4 4 4 1 15
7 3 3 3 9 9 9 9 4 1 15
12 1...

output:

5

result:

ok single line: '5'

Test #19:

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

input:

12 11
8 8 8 8 8 8 8 8 11 11 11
14 14 8 10 10 10 10 8 2 8 11
14 8 8 8 10 8 8 8 2 8 11
14 8 10 8 10 8 11 8 8 8 11
14 14 10 10 10 6 11 11 11 11 11
5 14 14 10 6 6 6 6 11 6 11
5 5 14 14 14 6 6 11 11 6 6
5 13 13 13 14 14 6 6 6 6 1
5 3 13 14 14 6 6 1 1 1 1
7 3 4 4 4 4 4 4 4 1 15
7 3 3 3 9 9 9 9 4 1 15
12 1...

output:

5

result:

ok single line: '5'

Test #20:

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

input:

100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ...

output:

101

result:

ok single line: '101'

Test #21:

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

input:

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

output:

2

result:

ok single line: '2'

Test #22:

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

input:

100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 3...

output:

100

result:

ok single line: '100'

Test #23:

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

input:

100 100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 3...

output:

99

result:

ok single line: '99'

Test #24:

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

input:

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

output:

4

result:

ok single line: '4'

Test #25:

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

input:

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

output:

4

result:

ok single line: '4'

Test #26:

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

input:

20 20
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 2 1 3 1 1 1 1 1 1 4 5 6 1 1 1 7 7 8 1
2 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 7 7 7 7
9 3 10 3 11 11 12 12 12 1 1 1 1 1 1 7 7 7 7 7
13 13 13 13 14 14 14 14 15 14 1 1 1 1 16 7 7 7 7 7
13 13 13 17 14 14 14 14 14 14 18 19 20 20 21 21 22 7 7 7
23 24 24 14 14 14 14...

output:

5

result:

ok single line: '5'

Test #27:

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

input:

18 4
6 6 12 12
13 3 3 5
13 21 21 5
13 4 4 5
13 32 32 5
7 7 14 14
8 15 15 16
8 2 2 16
8 27 27 16
1 1 9 9
17 11 11 10
17 35 35 10
18 19 26 22
20 19 26 25
28 19 26 31
30 19 26 34
33 19 26 24
29 19 26 23

output:

12

result:

ok single line: '12'

Test #28:

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

input:

50 50
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
3 4 1 1 1 1 1 1 1 2 2 2 2 5 2 6 6 2 2 2 2 2 2 2 7 7 8 2 2 2 9 2 2 2 10 2 2 2 2 2 2 2 2 2 2 11 12 2 2 2
13 13 1 1 1 1 1 1 1 1 2 2 14 2 2 2 15 2 2 16 2 17 17 2 7 7 8 18 18 19 20 20 21 22 10 10 2 2...

output:

7

result:

ok single line: '7'

Test #29:

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

input:

75 75
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
1 3 4 5 1 1 1 1 1 1 1 1 1 1 1 1 6 6 6 7 8 8 9 9 9 10 10 10 2 11 12 13 14 2 2 2 2 2 15 2 2 2 2 2 2 2 16 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 17 ...

output:

13

result:

ok single line: '13'

Test #30:

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

input:

60 20
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 1 1 1 1 3 1 1 1 1 1 1 1 4 1 1 1 5 1 1
6 1 1 7 7 8 8 9 1 1 1 10 10 4 1 1 1 1 11 11
12 12 1 13 7 8 8 1 1 1 1 1 14 4 1 1 1 1 15 15
16 17 1 13 7 1 1 1 1 1 18 1 1 19 20 21 21 22 22 22
16 17 23 24 24 1 25 26 1 1 1 1 1 1 1 27 27 22 22 22
28 28 28 28 29 30 25 ...

output:

9

result:

ok single line: '9'

Test #31:

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

input:

100 3
1 1 1
1 1 1
2 2 1
3 2 2
3 4 4
5 4 4
5 5 4
6 5 7
8 9 7
8 8 8
8 8 8
10 11 12
10 10 13
10 10 13
10 10 14
10 10 14
10 10 10
10 10 10
10 10 10
10 10 15
10 10 15
10 10 10
16 16 16
16 16 16
16 16 16
16 16 16
16 17 18
19 20 20
19 20 20
19 19 19
21 22 22
21 21 21
21 21 21
21 21 21
23 21 21
24 21 25
26 ...

output:

28

result:

ok single line: '28'

Test #32:

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

input:

10 100
1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
3 4 3 3 5 5 5 6 2 2 2 2 2 7 7 2 8 2 2 2 2 9 2 2 2 2 10 10 2 2 2 11 2 2 12 2 2 2 2 2 2 2 2 2 2...

output:

5

result:

ok single line: '5'

Test #33:

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

input:

30 75
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 3 3 1 1 4 1 5 1 1 1 6 7 1 1 1 1 1 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 1 1 10 10 11 1 1 1 1 1 1 1 1 1 12 12 12 13 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

5

result:

ok single line: '5'