QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#497339#9161. Naval battleQwerty1232#0 1ms3840kbC++235.3kb2024-07-29 01:57:422024-07-29 01:57:43

Judging History

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

  • [2024-07-29 01:57:43]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3840kb
  • [2024-07-29 01:57:42]
  • 提交

answer

#include <bits/stdc++.h>

constexpr std::string_view dir_ch = "ENWS";
constexpr std::array<std::pair<int, int>, 4> dlt = {{{1, 0}, {0, -1}, {-1, 0}, {0, 1}}};

struct Fuck {
    int x, y;
    int dir;
    int id;
};

int32_t main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    std::cin >> n;
    std::vector<Fuck> input(n);
    // for (auto& i : input) {
    for (int i = 0; i < n; i++) {
        std::cin >> input[i].x >> input[i].y;
        char ch;
        std::cin >> ch;
        input[i].dir = dir_ch.find(ch);
        input[i].id = i;
    }

    std::vector<std::set<std::array<int, 3>>> set;
    std::vector<std::set<std::array<int, 3>>> set2;
    std::multiset<std::array<int, 3>> set3;

    auto get_min = [&](int i) {
        auto &st = set[i];
        auto &st2 = set2[i];

        std::array<int, 3> min{(int)2.1e9, -1, -1};
        if (st.empty())
            return min;
        for (auto it = std::next(st.begin()); it != st.end(); it++) {
            auto [x1, d1, id1] = *std::prev(it);
            auto [x2, d2, id2] = *it;
            if (d1 == 1 && d2 == -1) {
                assert((x2 - x1) % 2 == 0);
                min = std::min(min, {(x2 - x1) / 2, id1, id2});
            }
        }
        return min;
    };
    auto insert = [&](int i, int x, int dr, int id) {
        if (i == -1) {
            return;
        }
        set3.extract(get_min(i));

        auto &st = set[i];
        auto &st2 = set2[i];
        st.insert({x, dr, id});

        set3.insert(get_min(i));
    };
    auto erase = [&](int i, int x, int dr, int id) {
        if (i == -1) {
            return;
        }
        set3.extract(get_min(i));

        auto &st = set[i];
        auto &st2 = set2[i];
        st.erase({x, dr, id});

        set3.insert(get_min(i));
    };
    // auto get_global_min = [&]() {
    //     return *set3.begin();
    // };

    std::vector<std::vector<std::array<int, 3>>> vec;
    for (auto [i, f] : std::vector<std::pair<int, int (*)(const Fuck &)>>{
             {0, [](const Fuck &a) -> int { return a.x; }},
             {1, [](const Fuck &a) -> int { return a.y; }},
             {2, [](const Fuck &a) -> int { return a.x + a.y; }},
             {3, [](const Fuck &a) -> int { return a.x + a.y; }},
             {4, [](const Fuck &a) -> int { return a.x - a.y; }},
             {5, [](const Fuck &a) -> int { return a.x - a.y; }}}) {
        vec.emplace_back(n);

        auto cmp = [&](auto a, auto b) { return f(a) < f(b); };
        std::sort(input.begin(), input.end(), cmp);

        for (int it = 0; it < input.size();) {
            int it2 = std::upper_bound(input.begin() + it, input.end(), input[it], cmp) - input.begin();
            // if (it + 1 == it2) {
            //     it++;
            //     continue;
            // }
            int s = set.size();
            set.push_back({}), set2.push_back({});
            auto &st = set.back();
            auto &st2 = set2.back();

            for (; it < it2; it++) {
                auto [x, y, dr, id] = input[it];
                vec[i][id].fill(-1);
                /*  */ if (i == 0 && (1 << dr & 0b10'10)) {
                    vec[i][id] = {s, x, (dir_ch[dr] == 'E') * 2 - 1};
                } else if (i == 1 && (1 << dr & 0b01'01)) {
                    vec[i][id] = {s, y, (dir_ch[dr] == 'S') * 2 - 1};
                } else if (i == 2 && (1 << dr & 0b10'01)) {
                    vec[i][id] = {s, y - x, (dir_ch[dr] == 'E') * 2 - 1};
                } else if (i == 3 && (1 << dr & 0b01'10)) {
                    vec[i][id] = {s, y - x, (dir_ch[dr] == 'W') * 2 - 1};
                } else if (i == 4 && (1 << dr & 0b00'11)) {
                    vec[i][id] = {s, x + y, (dir_ch[dr] == 'E') * 2 - 1};
                } else if (i == 5 && (1 << dr & 0b11'00)) {
                    vec[i][id] = {s, x + y, (dir_ch[dr] == 'S') * 2 - 1};
                }
                insert(vec[i][id][0], vec[i][id][1], vec[i][id][2], id);
            }
        }
    }

    std::sort(input.begin(), input.end(), [&](auto a, auto b) { return a.id < b.id; });
    std::map<std::pair<int, int>, int> map;
    for (auto f : input) {
        map[{f.x, f.y}] = f.id;
    }
    std::set<int> alive;
    for (int i = 0; i < n; i++) {
        alive.insert(i);
    }
    while (set3.size()) {
        auto [mn, id1, id2] = *set3.begin();
        if (id1 == -1) {
            break;
        }
        std::set<int> to_erase = {id1, id2};
        std::pair<int, int> pos = {input[id1].x + dlt[input[id1].dir].first * mn, input[id1].y + dlt[input[id1].dir].second * mn};
        for (int d = 0; d < 4; d++) {
            std::pair<int, int> pos2(pos.first + dlt[d].first * mn, pos.second + dlt[d].second * mn);
            int id = map.contains(pos2) ? map[pos2] : -1;
            if (id != -1) {
                if (input[id].dir == (d + 2) % 4) {
                    to_erase.insert(id);
                }
            }
        }
        for (auto id : to_erase) {
            alive.erase(id);
            for (int i = 0; i < vec.size(); i++) {
                erase(vec[i][id][0], vec[i][id][1], vec[i][id][2], id);
            }
        }
    }

    for (auto &i : alive) {
        std::cout << i + 1 << "\n";
    }

    return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 6
Accepted
time: 0ms
memory: 3840kb

input:

2
675333810 792019962 W
851860476 960355168 W

output:

1
2

result:

ok 

Test #2:

score: 6
Accepted
time: 0ms
memory: 3528kb

input:

2
714148610 688520844 W
359519570 789553998 S

output:

1
2

result:

ok 

Test #3:

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

input:

2
743286406 87591094 E
108453484 326740470 S

output:

1
2

result:

ok 

Test #4:

score: 6
Accepted
time: 0ms
memory: 3552kb

input:

2
629499666 659260200 W
391550936 897208930 N

output:


result:

ok 

Test #5:

score: 6
Accepted
time: 0ms
memory: 3608kb

input:

2
509095668 374922996 W
325521434 191348762 S

output:


result:

ok 

Test #6:

score: 0
Wrong Answer
time: 0ms
memory: 3576kb

input:

2
357656592 713571312 E
456601638 614626266 S

output:

1
2

result:

FAIL Unexpected end of file - token expected (/var/uoj_data/9161/6.ans)

Subtask #2:

score: 0
Wrong Answer

Test #14:

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

input:

100
32 46 N
8 24 W
74 86 W
2 76 N
90 70 N
34 74 N
4 68 N
42 26 N
66 94 N
28 40 W
96 12 W
82 78 W
54 24 N
36 42 W
92 68 W
0 26 N
14 54 N
94 66 N
26 52 N
66 12 W
72 6 W
64 96 W
6 20 N
4 22 W
26 42 N
40 28 W
70 76 N
18 60 N
62 16 N
30 48 N
36 36 W
42 36 W
52 94 N
62 98 N
0 78 N
70 2 W
28 50 N
80 80 W
8...

output:


result:

ok 

Test #15:

score: 12
Accepted
time: 1ms
memory: 3672kb

input:

100
70 62 N
56 42 N
42 56 W
64 4 N
50 48 W
56 76 N
78 20 W
96 96 W
60 72 N
44 24 N
2 10 N
52 80 W
38 30 N
94 4 W
58 74 W
68 30 W
54 76 N
0 68 N
36 32 N
10 58 W
70 60 W
86 92 N
100 78 W
2 66 W
20 48 N
16 52 N
8 60 N
98 94 N
86 46 W
74 24 W
26 42 W
66 66 W
28 40 W
56 12 W
90 42 W
8 4 W
76 30 W
78 54 W...

output:


result:

ok 

Test #16:

score: 0
Wrong Answer
time: 1ms
memory: 3700kb

input:

100
36 44 E
96 66 E
28 20 E
36 2 E
32 64 W
76 58 E
82 20 E
76 50 E
22 48 W
38 52 E
90 16 N
22 12 W
64 82 S
84 14 E
92 52 E
76 36 E
72 52 N
100 58 S
82 4 E
2 0 N
90 100 E
68 8 S
24 36 S
80 86 W
72 56 W
8 66 W
84 18 S
18 60 N
64 96 E
2 76 S
74 90 E
64 0 S
12 10 S
56 40 S
40 6 S
2 4 S
74 2 S
90 80 N
2 ...

output:

1
4
5
6
7
8
10
11
12
13
14
15
17
18
19
20
21
22
23
24
26
27
28
29
30
31
32
33
35
36
37
40
41
42
45
46
47
48
49
50
53
54
55
56
57
58
59
60
61
62
63
65
66
67
68
69
70
73
74
76
77
78
81
84
85
86
87
88
90
91
92
93
94
95
96
98
99

result:

FAIL Unexpected end of file - token expected (/var/uoj_data/9161/16.ans)

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Time Limit Exceeded

Test #58:

score: 0
Time Limit Exceeded

input:

200000
526715640 430855204 E
731546662 226024182 S
254814720 702756124 E
227354364 730216480 S
764250602 193320242 S
150102088 807468756 E
204858572 752712272 S
635512190 322058654 E
403910248 553660596 S
257917918 4587926 S
949444340 8126504 S
907805098 49765746 S
553836306 403734538 S
40977864 617...

output:


result:


Subtask #7:

score: 0
Skipped

Dependency #1:

0%