답안 #786018

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
786018 2023-07-17T22:17:10 Z sadsa 길고양이 (JOI20_stray) C++17
85 / 100
534 ms 15484 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;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 484 ms 15484 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 484 ms 15484 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 509 ms 13284 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 509 ms 13284 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 908 KB Output is correct
2 Correct 1 ms 516 KB Output is correct
3 Correct 12 ms 844 KB Output is correct
4 Correct 12 ms 896 KB Output is correct
5 Correct 12 ms 832 KB Output is correct
6 Correct 13 ms 872 KB Output is correct
7 Correct 12 ms 892 KB Output is correct
8 Correct 12 ms 904 KB Output is correct
9 Correct 12 ms 948 KB Output is correct
10 Correct 13 ms 872 KB Output is correct
11 Correct 15 ms 892 KB Output is correct
12 Correct 13 ms 876 KB Output is correct
13 Correct 12 ms 892 KB Output is correct
14 Correct 12 ms 920 KB Output is correct
15 Correct 13 ms 900 KB Output is correct
16 Correct 12 ms 904 KB Output is correct
17 Correct 13 ms 912 KB Output is correct
18 Correct 13 ms 900 KB Output is correct
19 Correct 12 ms 908 KB Output is correct
20 Correct 13 ms 904 KB Output is correct
21 Correct 15 ms 936 KB Output is correct
22 Correct 13 ms 908 KB Output is correct
23 Correct 12 ms 936 KB Output is correct
24 Correct 13 ms 884 KB Output is correct
25 Correct 13 ms 876 KB Output is correct
26 Correct 13 ms 1028 KB Output is correct
27 Correct 15 ms 844 KB Output is correct
28 Correct 12 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 489 ms 11736 KB Output is correct
2 Correct 504 ms 12304 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 488 ms 11624 KB Output is correct
5 Correct 477 ms 12724 KB Output is correct
6 Correct 460 ms 12740 KB Output is correct
7 Correct 494 ms 11944 KB Output is correct
8 Correct 478 ms 11748 KB Output is correct
9 Correct 492 ms 12776 KB Output is correct
10 Correct 474 ms 12900 KB Output is correct
11 Correct 480 ms 12792 KB Output is correct
12 Correct 522 ms 12740 KB Output is correct
13 Correct 488 ms 12704 KB Output is correct
14 Correct 485 ms 12760 KB Output is correct
15 Correct 458 ms 12744 KB Output is correct
16 Correct 526 ms 12812 KB Output is correct
17 Correct 483 ms 12408 KB Output is correct
18 Correct 498 ms 12452 KB Output is correct
19 Correct 459 ms 12388 KB Output is correct
20 Correct 512 ms 12412 KB Output is correct
21 Correct 464 ms 12424 KB Output is correct
22 Correct 454 ms 12412 KB Output is correct
23 Correct 456 ms 11748 KB Output is correct
24 Correct 446 ms 11768 KB Output is correct
25 Correct 452 ms 11756 KB Output is correct
26 Correct 444 ms 12240 KB Output is correct
27 Correct 493 ms 12400 KB Output is correct
28 Correct 459 ms 12360 KB Output is correct
29 Correct 459 ms 12376 KB Output is correct
30 Correct 457 ms 12368 KB Output is correct
31 Correct 467 ms 11764 KB Output is correct
32 Correct 448 ms 11584 KB Output is correct
33 Correct 512 ms 11796 KB Output is correct
34 Correct 443 ms 11972 KB Output is correct
35 Correct 513 ms 12368 KB Output is correct
36 Correct 472 ms 12236 KB Output is correct
37 Correct 457 ms 12252 KB Output is correct
38 Correct 458 ms 12648 KB Output is correct
39 Correct 472 ms 13116 KB Output is correct
40 Correct 455 ms 12848 KB Output is correct
41 Correct 496 ms 12860 KB Output is correct
42 Correct 451 ms 12912 KB Output is correct
43 Correct 461 ms 12844 KB Output is correct
44 Correct 464 ms 12940 KB Output is correct
45 Correct 456 ms 12916 KB Output is correct
46 Correct 470 ms 13192 KB Output is correct
47 Correct 447 ms 12616 KB Output is correct
48 Correct 496 ms 12784 KB Output is correct
49 Correct 482 ms 12584 KB Output is correct
50 Correct 450 ms 12608 KB Output is correct
51 Correct 475 ms 12432 KB Output is correct
52 Correct 456 ms 12384 KB Output is correct
53 Correct 470 ms 12336 KB Output is correct
54 Correct 440 ms 12340 KB Output is correct
55 Correct 453 ms 12456 KB Output is correct
56 Correct 444 ms 12304 KB Output is correct
57 Correct 459 ms 12380 KB Output is correct
58 Correct 457 ms 12396 KB Output is correct
59 Correct 452 ms 12288 KB Output is correct
60 Correct 441 ms 12432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 459 ms 11592 KB Output is correct
2 Correct 460 ms 11996 KB Output is correct
3 Correct 0 ms 508 KB Output is correct
4 Correct 442 ms 11620 KB Output is correct
5 Correct 446 ms 12724 KB Output is correct
6 Correct 459 ms 12648 KB Output is correct
7 Correct 448 ms 11868 KB Output is correct
8 Correct 471 ms 11864 KB Output is correct
9 Correct 490 ms 12768 KB Output is correct
10 Correct 452 ms 12680 KB Output is correct
11 Correct 461 ms 12784 KB Output is correct
12 Correct 448 ms 12692 KB Output is correct
13 Correct 458 ms 12740 KB Output is correct
14 Correct 456 ms 12692 KB Output is correct
15 Correct 454 ms 12732 KB Output is correct
16 Correct 453 ms 12936 KB Output is correct
17 Correct 443 ms 12436 KB Output is correct
18 Correct 475 ms 12556 KB Output is correct
19 Correct 449 ms 12680 KB Output is correct
20 Correct 453 ms 12480 KB Output is correct
21 Correct 453 ms 12676 KB Output is correct
22 Correct 443 ms 12460 KB Output is correct
23 Correct 463 ms 11692 KB Output is correct
24 Correct 448 ms 11660 KB Output is correct
25 Correct 440 ms 11792 KB Output is correct
26 Correct 510 ms 11836 KB Output is correct
27 Correct 502 ms 12308 KB Output is correct
28 Correct 466 ms 12356 KB Output is correct
29 Correct 477 ms 12428 KB Output is correct
30 Correct 456 ms 12532 KB Output is correct
31 Correct 477 ms 11672 KB Output is correct
32 Correct 481 ms 11680 KB Output is correct
33 Correct 451 ms 11712 KB Output is correct
34 Correct 452 ms 12044 KB Output is correct
35 Correct 454 ms 12288 KB Output is correct
36 Correct 496 ms 12204 KB Output is correct
37 Correct 516 ms 12796 KB Output is correct
38 Correct 504 ms 12716 KB Output is correct
39 Correct 498 ms 12692 KB Output is correct
40 Correct 492 ms 12736 KB Output is correct
41 Correct 474 ms 12860 KB Output is correct
42 Correct 510 ms 12924 KB Output is correct
43 Correct 503 ms 12960 KB Output is correct
44 Correct 486 ms 13076 KB Output is correct
45 Correct 490 ms 12880 KB Output is correct
46 Correct 533 ms 12904 KB Output is correct
47 Correct 497 ms 12412 KB Output is correct
48 Correct 485 ms 12632 KB Output is correct
49 Correct 472 ms 12436 KB Output is correct
50 Correct 534 ms 12600 KB Output is correct
51 Correct 467 ms 12480 KB Output is correct
52 Correct 470 ms 12508 KB Output is correct
53 Correct 453 ms 12392 KB Output is correct
54 Correct 454 ms 12420 KB Output is correct
55 Correct 464 ms 12340 KB Output is correct
56 Correct 467 ms 12416 KB Output is correct
57 Correct 472 ms 12280 KB Output is correct
58 Correct 453 ms 12356 KB Output is correct
59 Correct 496 ms 12260 KB Output is correct
60 Correct 496 ms 12184 KB Output is correct