답안 #387543

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
387543 2021-04-08T21:32:48 Z SorahISA Navigation 2 (JOI21_navigation2) C++17
100 / 100
1030 ms 1280 KB
#pragma GCC optimize("Ofast", "unroll-loops")
#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>;
template<typename T>
using Prior = std::priority_queue<T>;
template<typename T>
using prior = std::priority_queue<T, vector<T>, greater<T>>;

#define X first
#define Y second
#define eb emplace_back
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)

namespace {

int used[15], minUnused = 1;

int check(int nx, int ny, int gx, int gy) {
    if (abs(nx - gx) <= 1 and abs(ny - gy) <= 1) {
        int val = 3 * (gx-nx+1) + (gy-ny+1) + 1;
        return val;
    }
    if (ny+1 < gy) return 10;
    if (gy < ny-1) return 11;
    if (nx+1 < gx) return 12;
    if (gx < nx-1) return 13;
}

} // namespace

void Anna(int N, int K, vector<int> R, vector<int> C) {
    vector<vector<int>> flag;
    for (int k = 0; k < 9; ++k) {
        flag.assign(N, vector<int>(N, 0));
        memset(used, 0x00, sizeof(used)), minUnused = 1;
        
        for (int r = 0; r < N; ++r) {
            for (int c = 0; c < N; ++c) {
                int p = 3 * ((r+k/3) % 3) + ((c+k%3) % 3);
                if (p == 0) flag[r][c] = 14;
                if (1 <= p and p <= 7) flag[r][c] = check(r, c, R[p-1], C[p-1]);
                if (1 <= flag[r][c] and flag[r][c] <= 9) {
                    used[flag[r][c]] = 1;
                    // cerr << "(" << r << "," << c << "): " << flag[r][c] << "\n";
                }
            }
        }
        
        if (used[9]) continue; /// main difference from L = 13
        else {
            while (used[minUnused]) ++minUnused;
            // cerr << "minUnused:  " << minUnused << "\n";
            break;
        }
    }
    
    for (int r = 0; r < N; ++r) {
        for (int c = 0; c < N; ++c) flag[r][c] = flag[r][c] ? flag[r][c] : minUnused;
    }
    
    for (int r = 0; r < N; ++r) {
        for (int c = 0; c < N; ++c) {
            if (flag[r][c] >= 10) --flag[r][c];
            if (flag[r][c] > minUnused) --flag[r][c];
            SetFlag(r, c, flag[r][c]);
        }
    }
    
    // for (int r = 0; r < N; ++r) {
        // for (int c = 0; c < N; ++c) cerr << flag[r][c] << " \n"[c == N-1];
    // }
}

/*
11
100 7 45 45 55 55 65 65 37 29 48 16 45 44 46 45 55 65
100 7 45 45 55 55 65 65 37 29 48 16 45 44 46 45 65 55
100 7 45 45 55 55 65 65 37 29 48 16 45 44 46 45 45 55
100 7 45 45 55 55 65 65 37 29 48 16 45 44 46 45 55 45
100 7 45 45 55 55 65 65 37 29 48 16 45 44 46 45 45 64
100 7 45 45 55 55 65 65 37 29 48 16 45 44 46 45 45 65
100 7 45 45 55 55 65 65 37 29 48 16 45 44 46 45 65 45
100 7 45 45 55 55 65 65 37 29 48 16 45 44 46 45 45 54
100 7 45 45 55 55 65 65 37 29 48 16 45 44 46 45 54 45
100 7 45 45 55 55 65 65 37 29 48 16 45 44 46 45  1 98
100 7 39 48 67 19 35 29 88 60 95 12 47 71  3 86 24 19
*/
#pragma GCC optimize("Ofast", "unroll-loops")
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>;
template<typename T>
using Prior = std::priority_queue<T>;
template<typename T>
using prior = std::priority_queue<T, vector<T>, greater<T>>;

#define X first
#define Y second
#define eb emplace_back
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)

namespace {

int minUnused = 0;

vector<int> renumerate(vector<int> v) {
    vector<int> ret(9, -1);
    int p = -1;
    for (int i = 0; i < 9; ++i) if (v[i] == 12) p = i;
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            if (i == 0 and j == 0) continue;
            if (i == 2 and j == 2) {
                minUnused = v[3*((p/3+i)%3)+((p%3+j)%3)];
                continue;
            }
            ret[3*((p/3+i)%3)+((p%3+j)%3)] = 3*i+j-1;
        }
    }
    return ret;
}

} // namespace

vector<int> Bruno(int K, vector<int> v) {
    /// +x, -x, +y, -y, 0 ///
    // cerr << "Original:   "; for (auto x : v) cerr << x << " "; cerr << "\n";
    vector<int> id = renumerate(v);
    // cerr << "Renumerate: "; for (auto x : id) cerr << x << " "; cerr << "\n";
    // cerr << "minUnused:  " << minUnused << "\n";
    vector<int> res(K, -1);
    for (int i = 0; i < 9; i++) {
        if (id[i] == -1) continue;
        if (v[i] >= 8) res[id[i]] = v[i] - 8;
        else {
            v[i] += v[i] >= minUnused, --v[i];
            int dx = (i/3 - 1) + (v[i]/3 - 1), dy = (i%3 - 1) + (v[i]%3 - 1);
                 if (dy > 0) res[id[i]] = 0;
            else if (dy < 0) res[id[i]] = 1;
            else if (dx > 0) res[id[i]] = 2;
            else if (dx < 0) res[id[i]] = 3;
            else if (dx == 0 and dy == 0) res[id[i]] = 4;
        }
    }
    // for (auto x : res) cerr << x << " "; cerr << "\n";
    return res;
}

Compilation message

Anna.cpp: In function 'int {anonymous}::check(int, int, int, int)':
Anna.cpp:31:1: warning: control reaches end of non-void function [-Wreturn-type]
   31 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 728 KB Output is correct
2 Correct 15 ms 728 KB Output is correct
3 Correct 14 ms 728 KB Output is correct
4 Correct 14 ms 728 KB Output is correct
5 Correct 13 ms 728 KB Output is correct
6 Correct 16 ms 728 KB Output is correct
7 Correct 13 ms 728 KB Output is correct
8 Correct 15 ms 728 KB Output is correct
9 Correct 16 ms 728 KB Output is correct
10 Correct 12 ms 728 KB Output is correct
11 Correct 18 ms 728 KB Output is correct
12 Correct 15 ms 728 KB Output is correct
13 Correct 23 ms 728 KB Output is correct
14 Correct 14 ms 728 KB Output is correct
15 Correct 15 ms 728 KB Output is correct
16 Correct 15 ms 728 KB Output is correct
17 Correct 15 ms 600 KB Output is correct
18 Correct 16 ms 728 KB Output is correct
19 Correct 16 ms 728 KB Output is correct
20 Correct 13 ms 732 KB Output is correct
21 Correct 17 ms 728 KB Output is correct
22 Correct 15 ms 728 KB Output is correct
23 Correct 17 ms 728 KB Output is correct
24 Correct 16 ms 748 KB Output is correct
25 Correct 16 ms 748 KB Output is correct
26 Correct 17 ms 728 KB Output is correct
27 Correct 15 ms 728 KB Output is correct
28 Correct 16 ms 728 KB Output is correct
29 Correct 15 ms 728 KB Output is correct
30 Correct 16 ms 728 KB Output is correct
31 Correct 15 ms 728 KB Output is correct
32 Correct 12 ms 732 KB Output is correct
33 Correct 15 ms 728 KB Output is correct
34 Correct 15 ms 728 KB Output is correct
35 Correct 12 ms 728 KB Output is correct
36 Correct 12 ms 728 KB Output is correct
37 Correct 16 ms 728 KB Output is correct
38 Correct 13 ms 728 KB Output is correct
39 Correct 13 ms 728 KB Output is correct
40 Correct 16 ms 680 KB Output is correct
41 Correct 16 ms 728 KB Output is correct
42 Correct 17 ms 728 KB Output is correct
43 Correct 13 ms 728 KB Output is correct
44 Correct 19 ms 728 KB Output is correct
45 Correct 17 ms 728 KB Output is correct
46 Correct 20 ms 728 KB Output is correct
47 Correct 15 ms 728 KB Output is correct
48 Correct 15 ms 728 KB Output is correct
49 Correct 14 ms 728 KB Output is correct
50 Correct 18 ms 728 KB Output is correct
51 Correct 18 ms 728 KB Output is correct
52 Correct 18 ms 728 KB Output is correct
53 Correct 17 ms 728 KB Output is correct
54 Correct 18 ms 748 KB Output is correct
55 Correct 20 ms 728 KB Output is correct
56 Correct 17 ms 728 KB Output is correct
57 Correct 20 ms 728 KB Output is correct
58 Correct 17 ms 728 KB Output is correct
59 Correct 20 ms 728 KB Output is correct
60 Correct 24 ms 728 KB Output is correct
61 Correct 16 ms 728 KB Output is correct
62 Correct 21 ms 728 KB Output is correct
63 Correct 20 ms 728 KB Output is correct
64 Correct 19 ms 728 KB Output is correct
65 Correct 22 ms 748 KB Output is correct
66 Correct 24 ms 728 KB Output is correct
67 Correct 24 ms 728 KB Output is correct
68 Correct 20 ms 728 KB Output is correct
69 Correct 18 ms 728 KB Output is correct
70 Correct 27 ms 728 KB Output is correct
71 Correct 19 ms 728 KB Output is correct
72 Correct 17 ms 728 KB Output is correct
73 Correct 17 ms 728 KB Output is correct
74 Correct 20 ms 728 KB Output is correct
75 Correct 22 ms 728 KB Output is correct
76 Correct 24 ms 728 KB Output is correct
77 Correct 20 ms 728 KB Output is correct
78 Correct 20 ms 600 KB Output is correct
79 Correct 20 ms 728 KB Output is correct
80 Correct 17 ms 728 KB Output is correct
81 Correct 17 ms 728 KB Output is correct
82 Correct 20 ms 728 KB Output is correct
83 Correct 19 ms 676 KB Output is correct
84 Correct 20 ms 728 KB Output is correct
85 Correct 19 ms 728 KB Output is correct
86 Correct 17 ms 732 KB Output is correct
87 Correct 20 ms 728 KB Output is correct
88 Correct 23 ms 728 KB Output is correct
89 Correct 24 ms 728 KB Output is correct
90 Correct 26 ms 728 KB Output is correct
91 Correct 20 ms 728 KB Output is correct
92 Correct 24 ms 728 KB Output is correct
93 Correct 24 ms 728 KB Output is correct
94 Correct 19 ms 728 KB Output is correct
95 Correct 20 ms 728 KB Output is correct
96 Correct 18 ms 728 KB Output is correct
97 Correct 19 ms 728 KB Output is correct
98 Correct 18 ms 728 KB Output is correct
99 Correct 19 ms 728 KB Output is correct
100 Correct 22 ms 728 KB Output is correct
101 Correct 17 ms 728 KB Output is correct
102 Correct 23 ms 728 KB Output is correct
103 Correct 17 ms 728 KB Output is correct
104 Correct 18 ms 724 KB Output is correct
105 Correct 18 ms 728 KB Output is correct
106 Correct 21 ms 728 KB Output is correct
107 Correct 22 ms 728 KB Output is correct
108 Correct 17 ms 728 KB Output is correct
109 Correct 22 ms 728 KB Output is correct
110 Correct 18 ms 732 KB Output is correct
111 Correct 20 ms 728 KB Output is correct
112 Correct 19 ms 728 KB Output is correct
113 Correct 22 ms 728 KB Output is correct
114 Correct 20 ms 728 KB Output is correct
115 Correct 20 ms 732 KB Output is correct
116 Correct 24 ms 728 KB Output is correct
117 Correct 22 ms 728 KB Output is correct
118 Correct 23 ms 728 KB Output is correct
119 Correct 24 ms 728 KB Output is correct
120 Correct 815 ms 904 KB Output is correct
121 Correct 742 ms 896 KB Output is correct
122 Correct 770 ms 988 KB Output is correct
123 Correct 735 ms 900 KB Output is correct
124 Correct 839 ms 852 KB Output is correct
125 Correct 722 ms 1164 KB Output is correct
126 Correct 739 ms 1040 KB Output is correct
127 Correct 751 ms 904 KB Output is correct
128 Correct 741 ms 924 KB Output is correct
129 Correct 746 ms 812 KB Output is correct
130 Correct 755 ms 920 KB Output is correct
131 Correct 768 ms 1096 KB Output is correct
132 Correct 750 ms 1080 KB Output is correct
133 Correct 735 ms 944 KB Output is correct
134 Correct 761 ms 900 KB Output is correct
135 Correct 756 ms 932 KB Output is correct
136 Correct 795 ms 1184 KB Output is correct
137 Correct 763 ms 1024 KB Output is correct
138 Correct 723 ms 964 KB Output is correct
139 Correct 726 ms 824 KB Output is correct
140 Correct 721 ms 904 KB Output is correct
141 Correct 723 ms 884 KB Output is correct
142 Correct 733 ms 944 KB Output is correct
143 Correct 725 ms 928 KB Output is correct
144 Correct 771 ms 924 KB Output is correct
145 Correct 832 ms 1044 KB Output is correct
146 Correct 725 ms 1100 KB Output is correct
147 Correct 732 ms 912 KB Output is correct
148 Correct 949 ms 952 KB Output is correct
149 Correct 871 ms 1236 KB Output is correct
150 Correct 720 ms 856 KB Output is correct
151 Correct 748 ms 1280 KB Output is correct
152 Correct 818 ms 1144 KB Output is correct
153 Correct 814 ms 1032 KB Output is correct
154 Correct 723 ms 1136 KB Output is correct
155 Correct 721 ms 912 KB Output is correct
156 Correct 721 ms 888 KB Output is correct
157 Correct 737 ms 1196 KB Output is correct
158 Correct 749 ms 1124 KB Output is correct
159 Correct 1030 ms 916 KB Output is correct
160 Correct 767 ms 1056 KB Output is correct
161 Correct 740 ms 884 KB Output is correct
162 Correct 1002 ms 1024 KB Output is correct
163 Correct 730 ms 1052 KB Output is correct
164 Correct 799 ms 1016 KB Output is correct
165 Correct 731 ms 984 KB Output is correct
166 Correct 718 ms 944 KB Output is correct
167 Correct 719 ms 892 KB Output is correct
168 Correct 766 ms 860 KB Output is correct
169 Correct 744 ms 1036 KB Output is correct
170 Correct 750 ms 928 KB Output is correct
171 Correct 722 ms 900 KB Output is correct
172 Correct 733 ms 828 KB Output is correct
173 Correct 771 ms 932 KB Output is correct
174 Correct 796 ms 916 KB Output is correct
175 Correct 736 ms 924 KB Output is correct
176 Correct 747 ms 1068 KB Output is correct
177 Correct 735 ms 928 KB Output is correct
178 Correct 734 ms 952 KB Output is correct
179 Correct 724 ms 1132 KB Output is correct
180 Correct 728 ms 960 KB Output is correct
181 Correct 808 ms 836 KB Output is correct
182 Correct 751 ms 952 KB Output is correct
183 Correct 724 ms 1020 KB Output is correct
184 Correct 832 ms 1176 KB Output is correct
185 Correct 749 ms 956 KB Output is correct
186 Correct 832 ms 1084 KB Output is correct
187 Correct 724 ms 972 KB Output is correct
188 Correct 722 ms 924 KB Output is correct
189 Correct 726 ms 1104 KB Output is correct
190 Correct 837 ms 1004 KB Output is correct
191 Correct 880 ms 972 KB Output is correct
192 Correct 717 ms 900 KB Output is correct
193 Correct 749 ms 900 KB Output is correct
194 Correct 730 ms 952 KB Output is correct
195 Correct 744 ms 972 KB Output is correct
196 Correct 751 ms 984 KB Output is correct
197 Correct 763 ms 936 KB Output is correct
198 Correct 722 ms 932 KB Output is correct
199 Correct 773 ms 1044 KB Output is correct
200 Correct 754 ms 1052 KB Output is correct
201 Correct 737 ms 1116 KB Output is correct
202 Correct 894 ms 1140 KB Output is correct
203 Correct 732 ms 1092 KB Output is correct
204 Correct 829 ms 1076 KB Output is correct
205 Correct 749 ms 1012 KB Output is correct
206 Correct 748 ms 956 KB Output is correct
207 Correct 822 ms 1084 KB Output is correct
208 Correct 724 ms 988 KB Output is correct
209 Correct 871 ms 1064 KB Output is correct
210 Correct 640 ms 952 KB Output is correct
211 Correct 642 ms 948 KB Output is correct
212 Correct 592 ms 1004 KB Output is correct
213 Correct 554 ms 1132 KB Output is correct
214 Correct 570 ms 984 KB Output is correct
215 Correct 583 ms 856 KB Output is correct
216 Correct 591 ms 900 KB Output is correct
217 Correct 595 ms 1048 KB Output is correct
218 Correct 556 ms 832 KB Output is correct
219 Correct 559 ms 888 KB Output is correct
220 Correct 573 ms 924 KB Output is correct
221 Correct 555 ms 1012 KB Output is correct
222 Correct 594 ms 1100 KB Output is correct
223 Correct 695 ms 884 KB Output is correct
224 Correct 590 ms 864 KB Output is correct
225 Correct 587 ms 1240 KB Output is correct
226 Correct 571 ms 824 KB Output is correct