Submission #786021

# Submission time Handle Problem Language Result Execution time Memory
786021 2023-07-17T22:19:18 Z sadsa Stray Cat (JOI20_stray) C++17
85 / 100
40 ms 14792 KB
#include "Anthony.h"
#include <bits/stdc++.h>
using namespace std;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

using i64 = int64_t;
using vl = vector<i64>;
using ll = pair<i64, i64>;
using vll = vector<ll>;

constexpr int iINF = numeric_limits<int>::max();
constexpr i64 lINF = numeric_limits<i64>::max();

#define RANGE(x) begin(x), end(x)

template <typename... T>
void DBG(T&&... args) {
    //((cerr << args << ' '), ...) << '\n';
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &vec) {
    out << '{';
    for (size_t i = 0; i < vec.size()-1; ++i)
        out << vec[i] << ", ";
    out << vec.back() << '}';
    return out;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &pr) {
    out << '(' << pr.first << ", " << pr.second << ')';
    return out;
}

namespace {

vi Mark2d(int N, vi &U, vi &V) {
    int M = N-1;
    vi X(M, -1);

    vector<vector<pair<int,int>>> adj(N);

    for (int i = 0; i < M; ++i) {
        adj[U[i]].emplace_back(V[i], i);
        adj[V[i]].emplace_back(U[i], i);
    }

    DBG(adj);

    const vi sequence {1,0,1,0,0,1};

    queue<tuple<int, int, int>> q;

    for (auto [nxt, edge] : adj[0]) {
        X[edge] = sequence[0];
        q.emplace(nxt, 1, sequence[0]);
    }

    DBG("Mark");

    while (!q.empty()) {
        auto [crt, counter, prv] = q.front();
        q.pop();

        DBG(crt, counter);

        if (adj[crt].size() == 1) continue;
        if (adj[crt].size() == 2) {
            for (auto [nxt, edge] : adj[crt]) {
                if (X[edge] == -1) {
                    X[edge] = sequence[counter % sequence.size()];
                    q.emplace(nxt, counter+1, X[edge]);
                }
            }
        } else {
            for (auto [nxt, edge] : adj[crt]) {
                if (X[edge] == -1) {
                    X[edge] = !prv;
                    q.emplace(nxt, X[edge]? 1: 2, X[edge]);
                }
            }
        }
    }

    DBG(X);
    return X;

}

}  // namespace

std::vector<int> Mark(int N, int M, int A, int B,
                      std::vector<int> U, std::vector<int> V) {
    if (N == M+1) return Mark2d(N, U, V);
    while (1);
}

/*
7 6 2 6 3
6 5
5 0
0 1
1 2
2 3
3 4

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

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

*/
#include "Catherine.h"
#include <bits/stdc++.h>
using namespace std;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

using i64 = int64_t;
using vl = vector<i64>;
using ll = pair<i64, i64>;
using vll = vector<ll>;

constexpr int iINF = numeric_limits<int>::max();
constexpr i64 lINF = numeric_limits<i64>::max();

#define RANGE(x) begin(x), end(x)

template <typename... T>
void DBG(T&&... args) {
    //((cerr << args << ' '), ...) << '\n';
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &vec) {
    out << '{';
    for (size_t i = 0; i < vec.size()-1; ++i)
        out << vec[i] << ", ";
    out << vec.back() << '}';
    return out;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &pr) {
    out << '(' << pr.first << ", " << pr.second << ')';
    return out;
}

namespace {

int A, B;

bool found = false, first = true;
string current_path;
const string incr_way = "1101001101001";
const string decr_way = "1100101100101";

int prv = -1;

//             0      1
int move2d(int a, int b) {
    if (first) {
        DBG("FIRST!");
        int r;
        if (a+b == 1) {
            DBG("FOUND! by endpoint");
            found = true;
            r = a? 0: 1;
        } else if (a+b==2) {
            if (a == 2) {
                current_path = "00";
                r = 0;
            } else if (b == 2) {
                current_path = "11";
                r = 1;
            } else {
                current_path = "10";
                r = 0;
            }
        } else {
            DBG("FOUND! by intersection");

            r=-2;// not possible!
            if (a == 1) r = 0;
            if (b == 1) r = 1;
        }

        DBG("DONE FIRST:", r);
        first = false;
        return r;
    }

    if (a+b == 0) { // end point
        DBG("FOUND! by endpoint");
        found = true;
        return -1;
    }

    if (a+b >= 2) {
        DBG("FOUND! by intersection");
        found = true;
        if (a == 0 || b == 0) return -1;

        if (prv) b++;
        else a++;

        if (a == 1) return 0;
        if (b == 1) return 1;

        return -2; // not possible!
    }

    if (!found) {
        current_path += a? '0': '1';

        int correct = decr_way.find(current_path) != string::npos;
        int wrong = incr_way.find(current_path) != string::npos;

        DBG(current_path);
        found = true;
        if (correct + wrong == 2) found = false;
        else if (wrong) {
            DBG("FOUND! by wrong direction");
            return -1;
        }

        if (found) DBG("FOUND! by good direction");
    }

    if (a) return 0;
    else return 1;
}

}  // namespace

void Init(int A, int B) {
    ::A = A;
    ::B = B;
}

int Move(std::vector<int> y) {
    if (A == 2) return prv = move2d(y[0], y[1]);
    return -1;
}
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 14792 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 14792 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 12560 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 12560 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 896 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 904 KB Output is correct
4 Correct 2 ms 896 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 2 ms 772 KB Output is correct
7 Correct 2 ms 896 KB Output is correct
8 Correct 2 ms 896 KB Output is correct
9 Correct 2 ms 896 KB Output is correct
10 Correct 2 ms 896 KB Output is correct
11 Correct 2 ms 776 KB Output is correct
12 Correct 2 ms 768 KB Output is correct
13 Correct 2 ms 768 KB Output is correct
14 Correct 2 ms 776 KB Output is correct
15 Correct 2 ms 896 KB Output is correct
16 Correct 2 ms 900 KB Output is correct
17 Correct 2 ms 904 KB Output is correct
18 Correct 2 ms 904 KB Output is correct
19 Correct 2 ms 904 KB Output is correct
20 Correct 2 ms 768 KB Output is correct
21 Correct 2 ms 896 KB Output is correct
22 Correct 2 ms 904 KB Output is correct
23 Correct 2 ms 768 KB Output is correct
24 Correct 2 ms 768 KB Output is correct
25 Correct 2 ms 892 KB Output is correct
26 Correct 2 ms 780 KB Output is correct
27 Correct 2 ms 904 KB Output is correct
28 Correct 2 ms 904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 10852 KB Output is correct
2 Correct 26 ms 11316 KB Output is correct
3 Correct 0 ms 516 KB Output is correct
4 Correct 24 ms 10860 KB Output is correct
5 Correct 31 ms 11932 KB Output is correct
6 Correct 40 ms 11848 KB Output is correct
7 Correct 25 ms 10960 KB Output is correct
8 Correct 25 ms 10992 KB Output is correct
9 Correct 32 ms 11868 KB Output is correct
10 Correct 33 ms 11836 KB Output is correct
11 Correct 38 ms 11828 KB Output is correct
12 Correct 30 ms 11860 KB Output is correct
13 Correct 28 ms 11812 KB Output is correct
14 Correct 31 ms 11804 KB Output is correct
15 Correct 30 ms 11984 KB Output is correct
16 Correct 28 ms 11836 KB Output is correct
17 Correct 27 ms 11628 KB Output is correct
18 Correct 30 ms 11620 KB Output is correct
19 Correct 28 ms 11548 KB Output is correct
20 Correct 27 ms 11532 KB Output is correct
21 Correct 28 ms 11632 KB Output is correct
22 Correct 30 ms 11544 KB Output is correct
23 Correct 24 ms 10764 KB Output is correct
24 Correct 24 ms 10868 KB Output is correct
25 Correct 25 ms 10932 KB Output is correct
26 Correct 25 ms 11076 KB Output is correct
27 Correct 26 ms 11512 KB Output is correct
28 Correct 30 ms 11472 KB Output is correct
29 Correct 28 ms 11484 KB Output is correct
30 Correct 27 ms 11504 KB Output is correct
31 Correct 28 ms 10900 KB Output is correct
32 Correct 24 ms 10876 KB Output is correct
33 Correct 24 ms 10992 KB Output is correct
34 Correct 25 ms 10976 KB Output is correct
35 Correct 28 ms 11308 KB Output is correct
36 Correct 32 ms 11360 KB Output is correct
37 Correct 27 ms 11392 KB Output is correct
38 Correct 31 ms 11312 KB Output is correct
39 Correct 26 ms 11300 KB Output is correct
40 Correct 26 ms 11340 KB Output is correct
41 Correct 27 ms 11564 KB Output is correct
42 Correct 27 ms 11464 KB Output is correct
43 Correct 27 ms 11476 KB Output is correct
44 Correct 27 ms 11520 KB Output is correct
45 Correct 28 ms 11556 KB Output is correct
46 Correct 32 ms 11536 KB Output is correct
47 Correct 26 ms 11320 KB Output is correct
48 Correct 26 ms 11260 KB Output is correct
49 Correct 26 ms 11244 KB Output is correct
50 Correct 26 ms 11204 KB Output is correct
51 Correct 25 ms 11228 KB Output is correct
52 Correct 25 ms 11120 KB Output is correct
53 Correct 26 ms 11080 KB Output is correct
54 Correct 27 ms 10908 KB Output is correct
55 Correct 25 ms 11128 KB Output is correct
56 Correct 25 ms 11252 KB Output is correct
57 Correct 25 ms 11124 KB Output is correct
58 Correct 26 ms 11096 KB Output is correct
59 Correct 28 ms 10972 KB Output is correct
60 Correct 25 ms 11000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 10880 KB Output is correct
2 Correct 33 ms 11036 KB Output is correct
3 Correct 0 ms 508 KB Output is correct
4 Correct 22 ms 10872 KB Output is correct
5 Correct 30 ms 11848 KB Output is correct
6 Correct 30 ms 11884 KB Output is correct
7 Correct 25 ms 11104 KB Output is correct
8 Correct 25 ms 10988 KB Output is correct
9 Correct 30 ms 11868 KB Output is correct
10 Correct 30 ms 11868 KB Output is correct
11 Correct 34 ms 11864 KB Output is correct
12 Correct 36 ms 11860 KB Output is correct
13 Correct 34 ms 11900 KB Output is correct
14 Correct 36 ms 11796 KB Output is correct
15 Correct 30 ms 11880 KB Output is correct
16 Correct 28 ms 11920 KB Output is correct
17 Correct 28 ms 11596 KB Output is correct
18 Correct 27 ms 11600 KB Output is correct
19 Correct 27 ms 11624 KB Output is correct
20 Correct 27 ms 11628 KB Output is correct
21 Correct 31 ms 11668 KB Output is correct
22 Correct 27 ms 11632 KB Output is correct
23 Correct 25 ms 10740 KB Output is correct
24 Correct 24 ms 10860 KB Output is correct
25 Correct 27 ms 10940 KB Output is correct
26 Correct 28 ms 11000 KB Output is correct
27 Correct 28 ms 11364 KB Output is correct
28 Correct 28 ms 11508 KB Output is correct
29 Correct 26 ms 11488 KB Output is correct
30 Correct 26 ms 11500 KB Output is correct
31 Correct 24 ms 10788 KB Output is correct
32 Correct 25 ms 10864 KB Output is correct
33 Correct 26 ms 10984 KB Output is correct
34 Correct 27 ms 10948 KB Output is correct
35 Correct 26 ms 11444 KB Output is correct
36 Correct 34 ms 11384 KB Output is correct
37 Correct 37 ms 11344 KB Output is correct
38 Correct 26 ms 11448 KB Output is correct
39 Correct 26 ms 11356 KB Output is correct
40 Correct 26 ms 11368 KB Output is correct
41 Correct 31 ms 11628 KB Output is correct
42 Correct 28 ms 11552 KB Output is correct
43 Correct 31 ms 11512 KB Output is correct
44 Correct 27 ms 11648 KB Output is correct
45 Correct 27 ms 11564 KB Output is correct
46 Correct 27 ms 11572 KB Output is correct
47 Correct 27 ms 11344 KB Output is correct
48 Correct 26 ms 11248 KB Output is correct
49 Correct 26 ms 11224 KB Output is correct
50 Correct 27 ms 11376 KB Output is correct
51 Correct 24 ms 11116 KB Output is correct
52 Correct 25 ms 11260 KB Output is correct
53 Correct 24 ms 11220 KB Output is correct
54 Correct 25 ms 11220 KB Output is correct
55 Correct 28 ms 11156 KB Output is correct
56 Correct 26 ms 11208 KB Output is correct
57 Correct 25 ms 11116 KB Output is correct
58 Correct 25 ms 11076 KB Output is correct
59 Correct 25 ms 11008 KB Output is correct
60 Correct 25 ms 10956 KB Output is correct