답안 #786022

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
786022 2023-07-17T22:22:26 Z sadsa 길고양이 (JOI20_stray) C++17
85 / 100
42 ms 16056 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) {
    return prv = move2d(y[0], y[1]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 14960 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 24 ms 14904 KB Output is correct
4 Correct 35 ms 16052 KB Output is correct
5 Incorrect 39 ms 16056 KB Wrong Answer [6]
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 14960 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 24 ms 14904 KB Output is correct
4 Correct 35 ms 16052 KB Output is correct
5 Incorrect 39 ms 16056 KB Wrong Answer [6]
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 12548 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 22 ms 12756 KB Output is correct
4 Correct 32 ms 13848 KB Output is correct
5 Incorrect 39 ms 13808 KB Wrong Answer [6]
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 12548 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 22 ms 12756 KB Output is correct
4 Correct 32 ms 13848 KB Output is correct
5 Incorrect 39 ms 13808 KB Wrong Answer [6]
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 896 KB Output is correct
2 Correct 0 ms 508 KB Output is correct
3 Correct 2 ms 904 KB Output is correct
4 Correct 2 ms 904 KB Output is correct
5 Correct 2 ms 776 KB Output is correct
6 Correct 2 ms 900 KB Output is correct
7 Correct 2 ms 904 KB Output is correct
8 Correct 2 ms 896 KB Output is correct
9 Correct 2 ms 764 KB Output is correct
10 Correct 2 ms 856 KB Output is correct
11 Correct 2 ms 896 KB Output is correct
12 Correct 2 ms 896 KB Output is correct
13 Correct 2 ms 904 KB Output is correct
14 Correct 2 ms 880 KB Output is correct
15 Correct 2 ms 896 KB Output is correct
16 Correct 2 ms 896 KB Output is correct
17 Correct 2 ms 896 KB Output is correct
18 Correct 2 ms 896 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 776 KB Output is correct
23 Correct 2 ms 768 KB Output is correct
24 Correct 2 ms 896 KB Output is correct
25 Correct 2 ms 896 KB Output is correct
26 Correct 2 ms 904 KB Output is correct
27 Correct 2 ms 908 KB Output is correct
28 Correct 2 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 10788 KB Output is correct
2 Correct 26 ms 11372 KB Output is correct
3 Correct 0 ms 508 KB Output is correct
4 Correct 20 ms 10860 KB Output is correct
5 Correct 30 ms 11848 KB Output is correct
6 Correct 31 ms 11892 KB Output is correct
7 Correct 25 ms 10996 KB Output is correct
8 Correct 25 ms 10976 KB Output is correct
9 Correct 28 ms 11852 KB Output is correct
10 Correct 28 ms 11888 KB Output is correct
11 Correct 36 ms 11872 KB Output is correct
12 Correct 39 ms 11784 KB Output is correct
13 Correct 34 ms 11880 KB Output is correct
14 Correct 42 ms 11808 KB Output is correct
15 Correct 30 ms 11920 KB Output is correct
16 Correct 30 ms 11864 KB Output is correct
17 Correct 27 ms 11672 KB Output is correct
18 Correct 35 ms 11584 KB Output is correct
19 Correct 33 ms 11548 KB Output is correct
20 Correct 28 ms 11612 KB Output is correct
21 Correct 28 ms 11616 KB Output is correct
22 Correct 31 ms 11692 KB Output is correct
23 Correct 24 ms 10832 KB Output is correct
24 Correct 24 ms 10724 KB Output is correct
25 Correct 26 ms 10972 KB Output is correct
26 Correct 25 ms 10940 KB Output is correct
27 Correct 28 ms 11428 KB Output is correct
28 Correct 32 ms 11444 KB Output is correct
29 Correct 26 ms 11412 KB Output is correct
30 Correct 26 ms 11480 KB Output is correct
31 Correct 25 ms 10764 KB Output is correct
32 Correct 24 ms 10876 KB Output is correct
33 Correct 24 ms 11000 KB Output is correct
34 Correct 25 ms 10916 KB Output is correct
35 Correct 26 ms 11312 KB Output is correct
36 Correct 26 ms 11420 KB Output is correct
37 Correct 26 ms 11372 KB Output is correct
38 Correct 26 ms 11376 KB Output is correct
39 Correct 27 ms 11356 KB Output is correct
40 Correct 27 ms 11308 KB Output is correct
41 Correct 32 ms 11496 KB Output is correct
42 Correct 31 ms 11524 KB Output is correct
43 Correct 33 ms 11568 KB Output is correct
44 Correct 27 ms 11700 KB Output is correct
45 Correct 31 ms 11536 KB Output is correct
46 Correct 30 ms 11632 KB Output is correct
47 Correct 32 ms 11252 KB Output is correct
48 Correct 26 ms 11228 KB Output is correct
49 Correct 27 ms 11240 KB Output is correct
50 Correct 26 ms 11260 KB Output is correct
51 Correct 25 ms 11180 KB Output is correct
52 Correct 28 ms 11084 KB Output is correct
53 Correct 24 ms 11076 KB Output is correct
54 Correct 24 ms 11164 KB Output is correct
55 Correct 25 ms 11248 KB Output is correct
56 Correct 25 ms 11176 KB Output is correct
57 Correct 26 ms 11116 KB Output is correct
58 Correct 32 ms 11100 KB Output is correct
59 Correct 26 ms 10988 KB Output is correct
60 Correct 24 ms 10932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 10856 KB Output is correct
2 Correct 25 ms 11248 KB Output is correct
3 Correct 0 ms 516 KB Output is correct
4 Correct 20 ms 10840 KB Output is correct
5 Correct 30 ms 11788 KB Output is correct
6 Correct 28 ms 11884 KB Output is correct
7 Correct 25 ms 11036 KB Output is correct
8 Correct 26 ms 10988 KB Output is correct
9 Correct 39 ms 11808 KB Output is correct
10 Correct 33 ms 11852 KB Output is correct
11 Correct 28 ms 11964 KB Output is correct
12 Correct 28 ms 11900 KB Output is correct
13 Correct 30 ms 11900 KB Output is correct
14 Correct 28 ms 11876 KB Output is correct
15 Correct 30 ms 11880 KB Output is correct
16 Correct 28 ms 11888 KB Output is correct
17 Correct 26 ms 11616 KB Output is correct
18 Correct 34 ms 11480 KB Output is correct
19 Correct 35 ms 11568 KB Output is correct
20 Correct 31 ms 11620 KB Output is correct
21 Correct 28 ms 11596 KB Output is correct
22 Correct 27 ms 11592 KB Output is correct
23 Correct 25 ms 10856 KB Output is correct
24 Correct 25 ms 10860 KB Output is correct
25 Correct 24 ms 10992 KB Output is correct
26 Correct 26 ms 10968 KB Output is correct
27 Correct 26 ms 11500 KB Output is correct
28 Correct 27 ms 11452 KB Output is correct
29 Correct 31 ms 11412 KB Output is correct
30 Correct 30 ms 11492 KB Output is correct
31 Correct 24 ms 10816 KB Output is correct
32 Correct 28 ms 10768 KB Output is correct
33 Correct 25 ms 10948 KB Output is correct
34 Correct 25 ms 10952 KB Output is correct
35 Correct 26 ms 11324 KB Output is correct
36 Correct 26 ms 11352 KB Output is correct
37 Correct 31 ms 11356 KB Output is correct
38 Correct 26 ms 11368 KB Output is correct
39 Correct 28 ms 11296 KB Output is correct
40 Correct 26 ms 11372 KB Output is correct
41 Correct 28 ms 11440 KB Output is correct
42 Correct 38 ms 11516 KB Output is correct
43 Correct 27 ms 11512 KB Output is correct
44 Correct 27 ms 11492 KB Output is correct
45 Correct 27 ms 11600 KB Output is correct
46 Correct 30 ms 11624 KB Output is correct
47 Correct 26 ms 11232 KB Output is correct
48 Correct 27 ms 11232 KB Output is correct
49 Correct 27 ms 11144 KB Output is correct
50 Correct 30 ms 11388 KB Output is correct
51 Correct 25 ms 11196 KB Output is correct
52 Correct 25 ms 11248 KB Output is correct
53 Correct 26 ms 11232 KB Output is correct
54 Correct 24 ms 11224 KB Output is correct
55 Correct 25 ms 11064 KB Output is correct
56 Correct 25 ms 11248 KB Output is correct
57 Correct 28 ms 11084 KB Output is correct
58 Correct 24 ms 11084 KB Output is correct
59 Correct 28 ms 11028 KB Output is correct
60 Correct 27 ms 10940 KB Output is correct