Submission #1010147

# Submission time Handle Problem Language Result Execution time Memory
1010147 2024-06-28T11:24:16 Z Unforgettablepl Navigation 2 (JOI21_navigation2) C++17
100 / 100
567 ms 1756 KB
#include "Anna.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;


namespace {

vector<vector<int>> assignment = {
    {0,1,2},
    {3,4,5},
    {6,8,7},
};

} // namespace

void Anna(int N, int K, std::vector<int> R, std::vector<int> C) {
    int offset_x=0;
    int offset_y=0;
    vector<vector<int>> flags(N,vector<int>(N));
    re:
    vector<bool> used(14);
    assert(offset_x!=3);
    for (int r = 0; r < N; r++) {
        for (int c = 0; c < N; c++) {
            if(assignment[(r+offset_x)%3][(c+offset_y)%3]==7 or assignment[(r+offset_x)%3][(c+offset_y)%3]==8){flags[r][c]=(r,c,13);continue;}
            auto ass = assignment[(r+offset_x)%3][(c+offset_y)%3];
            if(abs(R[ass]-r)<=1 and abs(C[ass]-c)<=1){
                if(R[ass]==r and C[ass]==c){
                    // Redo
                    if(offset_y==2){
                        offset_x++;
                        offset_y=0;
                    } else offset_y++;
                    goto re;
                }
                else if(R[ass]==r-1 and C[ass]==c)flags[r][c]=(r,c,12);
                else if(R[ass]==r-1 and C[ass]==c-1)flags[r][c]=(r,c,11);
                else if(R[ass]==r-1 and C[ass]==c+1)flags[r][c]=(r,c,5);
                else if(R[ass]==r and C[ass]==c-1)flags[r][c]=(r,c,10);
                else if(R[ass]==r and C[ass]==c+1)flags[r][c]=(r,c,6);
                else if(R[ass]==r+1 and C[ass]==c-1)flags[r][c]=(r,c,9);
                else if(R[ass]==r+1 and C[ass]==c)flags[r][c]=(r,c,8);
                else if(R[ass]==r+1 and C[ass]==c+1)flags[r][c]=(r,c,7);
                continue;
            }
            if(abs(R[ass]-r)<=1){
                if(c<C[ass])flags[r][c]=(r,c,2);
                else if(C[ass]<c)flags[r][c]=(r,c,4);
                continue;
            }
            if(r<R[ass])flags[r][c]=(r,c,3);
            else if(R[ass]<r)flags[r][c]=(r,c,1);
        }
    }
    for(int i=0;i<N;i++)for(int j=0;j<N;j++)used[flags[i][j]]=true;
    for(int x=1;x<14;x++)if(!used[x]){
        for(int i=0;i<N;i++)for(int j=0;j<N;j++)if(flags[i][j]>=x)flags[i][j]--;
        for(int i=0;i<N;i++)for(int j=0;j<N;j++)if(assignment[(i+offset_x)%3][(j+offset_y)%3]==8)flags[i][j]=x;
        for(int i=0;i<N;i++)for(int j=0;j<N;j++)SetFlag(i,j,flags[i][j]);
        return;
    }
    if(offset_y==2){
        offset_x++;
        offset_y=0;
    } else offset_y++;
    goto re;
}
#include "Bruno.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;


namespace {

vector<pair<int,int>> idxlookup = {
    {0,0},
    {0,1},
    {0,2},
    {1,0},
    {1,1},
    {1,2},
    {2,0},
    {2,1},
};

} // namespace

std::vector<int> Bruno(int K, std::vector<int> value) {
    vector<vector<int>> val = {
        {value[0],value[1],value[2]},
        {value[3],value[4],value[5]},
        {value[6],value[7],value[8]},
    };
    vector<int> ans(K, 0);
    int rowoffset = 0;
    if(val[0][0]==12 or val[0][1]==12 or val[0][2]==12)rowoffset=1;
    if(val[1][0]==12 or val[1][1]==12 or val[1][2]==12)rowoffset=2;
    if(val[2][0]==12 or val[2][1]==12 or val[2][2]==12)rowoffset=0;
    int coloffset = 0;
    if(val[(rowoffset+2)%3][1]==12 and val[(rowoffset+2)%3][2]==12)coloffset=0;
    else if(val[(rowoffset+2)%3][0]==12 and val[(rowoffset+2)%3][1]==12)coloffset=2;
    else if(val[(rowoffset+2)%3][0]==12 and val[(rowoffset+2)%3][2]==12)coloffset=1;
    else if(val[(rowoffset+2)%3][0]==12)coloffset=1;
    else if(val[(rowoffset+2)%3][1]==12)coloffset=2;
    else if(val[(rowoffset+2)%3][2]==12)coloffset=0;
    int unusedoffset = val[(idxlookup[7].first+rowoffset)%3][(idxlookup[7].second+coloffset)%3];
    for(auto&i:val)for(int&j:i)if(j>=unusedoffset)j++;
    for(int i=0;i<K;i++){
        int act_x = (idxlookup[i].first+rowoffset)%3;
        int act_y = (idxlookup[i].second+coloffset)%3;
        if(val[act_x][act_y]==1){ans[i]=3;continue;}
        if(val[act_x][act_y]==2){ans[i]=0;continue;}
        if(val[act_x][act_y]==3){ans[i]=2;continue;}
        if(val[act_x][act_y]==4){ans[i]=1;continue;}
        int where_x = act_x;
        int where_y = act_y;
        if(val[act_x][act_y]==12){where_x+=-1;where_y+=0;}
        if(val[act_x][act_y]==11){where_x+=-1;where_y+=-1;}
        if(val[act_x][act_y]==10){where_x+=0;where_y+=-1;}
        if(val[act_x][act_y]==6){where_x+=0;where_y+=1;}
        if(val[act_x][act_y]==5){where_x+=-1;where_y+=1;}
        if(val[act_x][act_y]==9){where_x+=1;where_y+=-1;}
        if(val[act_x][act_y]==8){where_x+=1;where_y+=0;}
        if(val[act_x][act_y]==7){where_x+=1;where_y+=1;}
        if(where_x==1 and where_y==1){ans[i]=4;continue;}
        if(where_x<1){ans[i]=3;continue;}
        if(where_x>1){ans[i]=2;continue;}
        if(where_y<1){ans[i]=1;continue;}
        if(where_y>1){ans[i]=0;continue;}
    }
    return ans;
}

Compilation message

Anna.cpp: In function 'void Anna(int, int, std::vector<int>, std::vector<int>)':
Anna.cpp:26:125: warning: left operand of comma operator has no effect [-Wunused-value]
   26 |             if(assignment[(r+offset_x)%3][(c+offset_y)%3]==7 or assignment[(r+offset_x)%3][(c+offset_y)%3]==8){flags[r][c]=(r,c,13);continue;}
      |                                                                                                                             ^
Anna.cpp:26:129: warning: right operand of comma operator has no effect [-Wunused-value]
   26 |             if(assignment[(r+offset_x)%3][(c+offset_y)%3]==7 or assignment[(r+offset_x)%3][(c+offset_y)%3]==8){flags[r][c]=(r,c,13);continue;}
      |                                                                                                                                 ^~
Anna.cpp:37:64: warning: left operand of comma operator has no effect [-Wunused-value]
   37 |                 else if(R[ass]==r-1 and C[ass]==c)flags[r][c]=(r,c,12);
      |                                                                ^
Anna.cpp:37:68: warning: right operand of comma operator has no effect [-Wunused-value]
   37 |                 else if(R[ass]==r-1 and C[ass]==c)flags[r][c]=(r,c,12);
      |                                                                    ^~
Anna.cpp:38:66: warning: left operand of comma operator has no effect [-Wunused-value]
   38 |                 else if(R[ass]==r-1 and C[ass]==c-1)flags[r][c]=(r,c,11);
      |                                                                  ^
Anna.cpp:38:70: warning: right operand of comma operator has no effect [-Wunused-value]
   38 |                 else if(R[ass]==r-1 and C[ass]==c-1)flags[r][c]=(r,c,11);
      |                                                                      ^~
Anna.cpp:39:66: warning: left operand of comma operator has no effect [-Wunused-value]
   39 |                 else if(R[ass]==r-1 and C[ass]==c+1)flags[r][c]=(r,c,5);
      |                                                                  ^
Anna.cpp:39:70: warning: right operand of comma operator has no effect [-Wunused-value]
   39 |                 else if(R[ass]==r-1 and C[ass]==c+1)flags[r][c]=(r,c,5);
      |                                                                      ^
Anna.cpp:40:64: warning: left operand of comma operator has no effect [-Wunused-value]
   40 |                 else if(R[ass]==r and C[ass]==c-1)flags[r][c]=(r,c,10);
      |                                                                ^
Anna.cpp:40:68: warning: right operand of comma operator has no effect [-Wunused-value]
   40 |                 else if(R[ass]==r and C[ass]==c-1)flags[r][c]=(r,c,10);
      |                                                                    ^~
Anna.cpp:41:64: warning: left operand of comma operator has no effect [-Wunused-value]
   41 |                 else if(R[ass]==r and C[ass]==c+1)flags[r][c]=(r,c,6);
      |                                                                ^
Anna.cpp:41:68: warning: right operand of comma operator has no effect [-Wunused-value]
   41 |                 else if(R[ass]==r and C[ass]==c+1)flags[r][c]=(r,c,6);
      |                                                                    ^
Anna.cpp:42:66: warning: left operand of comma operator has no effect [-Wunused-value]
   42 |                 else if(R[ass]==r+1 and C[ass]==c-1)flags[r][c]=(r,c,9);
      |                                                                  ^
Anna.cpp:42:70: warning: right operand of comma operator has no effect [-Wunused-value]
   42 |                 else if(R[ass]==r+1 and C[ass]==c-1)flags[r][c]=(r,c,9);
      |                                                                      ^
Anna.cpp:43:64: warning: left operand of comma operator has no effect [-Wunused-value]
   43 |                 else if(R[ass]==r+1 and C[ass]==c)flags[r][c]=(r,c,8);
      |                                                                ^
Anna.cpp:43:68: warning: right operand of comma operator has no effect [-Wunused-value]
   43 |                 else if(R[ass]==r+1 and C[ass]==c)flags[r][c]=(r,c,8);
      |                                                                    ^
Anna.cpp:44:66: warning: left operand of comma operator has no effect [-Wunused-value]
   44 |                 else if(R[ass]==r+1 and C[ass]==c+1)flags[r][c]=(r,c,7);
      |                                                                  ^
Anna.cpp:44:70: warning: right operand of comma operator has no effect [-Wunused-value]
   44 |                 else if(R[ass]==r+1 and C[ass]==c+1)flags[r][c]=(r,c,7);
      |                                                                      ^
Anna.cpp:48:42: warning: left operand of comma operator has no effect [-Wunused-value]
   48 |                 if(c<C[ass])flags[r][c]=(r,c,2);
      |                                          ^
Anna.cpp:48:46: warning: right operand of comma operator has no effect [-Wunused-value]
   48 |                 if(c<C[ass])flags[r][c]=(r,c,2);
      |                                              ^
Anna.cpp:49:47: warning: left operand of comma operator has no effect [-Wunused-value]
   49 |                 else if(C[ass]<c)flags[r][c]=(r,c,4);
      |                                               ^
Anna.cpp:49:51: warning: right operand of comma operator has no effect [-Wunused-value]
   49 |                 else if(C[ass]<c)flags[r][c]=(r,c,4);
      |                                                   ^
Anna.cpp:52:38: warning: left operand of comma operator has no effect [-Wunused-value]
   52 |             if(r<R[ass])flags[r][c]=(r,c,3);
      |                                      ^
Anna.cpp:52:42: warning: right operand of comma operator has no effect [-Wunused-value]
   52 |             if(r<R[ass])flags[r][c]=(r,c,3);
      |                                          ^
Anna.cpp:53:43: warning: left operand of comma operator has no effect [-Wunused-value]
   53 |             else if(R[ass]<r)flags[r][c]=(r,c,1);
      |                                           ^
Anna.cpp:53:47: warning: right operand of comma operator has no effect [-Wunused-value]
   53 |             else if(R[ass]<r)flags[r][c]=(r,c,1);
      |                                               ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 664 KB Output is correct
2 Correct 5 ms 664 KB Output is correct
3 Correct 8 ms 664 KB Output is correct
4 Correct 7 ms 664 KB Output is correct
5 Correct 7 ms 664 KB Output is correct
6 Correct 7 ms 664 KB Output is correct
7 Correct 6 ms 664 KB Output is correct
8 Correct 8 ms 664 KB Output is correct
9 Correct 6 ms 664 KB Output is correct
10 Correct 8 ms 664 KB Output is correct
11 Correct 10 ms 664 KB Output is correct
12 Correct 8 ms 752 KB Output is correct
13 Correct 7 ms 664 KB Output is correct
14 Correct 7 ms 664 KB Output is correct
15 Correct 9 ms 748 KB Output is correct
16 Correct 5 ms 664 KB Output is correct
17 Correct 6 ms 664 KB Output is correct
18 Correct 5 ms 664 KB Output is correct
19 Correct 7 ms 676 KB Output is correct
20 Correct 6 ms 664 KB Output is correct
21 Correct 6 ms 664 KB Output is correct
22 Correct 5 ms 664 KB Output is correct
23 Correct 8 ms 664 KB Output is correct
24 Correct 7 ms 664 KB Output is correct
25 Correct 8 ms 712 KB Output is correct
26 Correct 8 ms 748 KB Output is correct
27 Correct 5 ms 664 KB Output is correct
28 Correct 7 ms 664 KB Output is correct
29 Correct 7 ms 664 KB Output is correct
30 Correct 6 ms 664 KB Output is correct
31 Correct 7 ms 664 KB Output is correct
32 Correct 7 ms 664 KB Output is correct
33 Correct 7 ms 664 KB Output is correct
34 Correct 6 ms 664 KB Output is correct
35 Correct 7 ms 664 KB Output is correct
36 Correct 5 ms 664 KB Output is correct
37 Correct 6 ms 664 KB Output is correct
38 Correct 7 ms 664 KB Output is correct
39 Correct 9 ms 664 KB Output is correct
40 Correct 9 ms 664 KB Output is correct
41 Correct 6 ms 744 KB Output is correct
42 Correct 7 ms 664 KB Output is correct
43 Correct 9 ms 664 KB Output is correct
44 Correct 7 ms 664 KB Output is correct
45 Correct 8 ms 664 KB Output is correct
46 Correct 7 ms 664 KB Output is correct
47 Correct 9 ms 664 KB Output is correct
48 Correct 10 ms 664 KB Output is correct
49 Correct 12 ms 664 KB Output is correct
50 Correct 7 ms 664 KB Output is correct
51 Correct 8 ms 748 KB Output is correct
52 Correct 8 ms 664 KB Output is correct
53 Correct 9 ms 664 KB Output is correct
54 Correct 9 ms 664 KB Output is correct
55 Correct 9 ms 728 KB Output is correct
56 Correct 11 ms 664 KB Output is correct
57 Correct 14 ms 664 KB Output is correct
58 Correct 9 ms 664 KB Output is correct
59 Correct 15 ms 920 KB Output is correct
60 Correct 9 ms 664 KB Output is correct
61 Correct 9 ms 664 KB Output is correct
62 Correct 14 ms 664 KB Output is correct
63 Correct 9 ms 916 KB Output is correct
64 Correct 11 ms 664 KB Output is correct
65 Correct 14 ms 664 KB Output is correct
66 Correct 13 ms 664 KB Output is correct
67 Correct 12 ms 664 KB Output is correct
68 Correct 12 ms 664 KB Output is correct
69 Correct 8 ms 664 KB Output is correct
70 Correct 9 ms 668 KB Output is correct
71 Correct 8 ms 668 KB Output is correct
72 Correct 9 ms 664 KB Output is correct
73 Correct 9 ms 664 KB Output is correct
74 Correct 13 ms 664 KB Output is correct
75 Correct 12 ms 664 KB Output is correct
76 Correct 15 ms 668 KB Output is correct
77 Correct 12 ms 668 KB Output is correct
78 Correct 9 ms 664 KB Output is correct
79 Correct 9 ms 664 KB Output is correct
80 Correct 12 ms 664 KB Output is correct
81 Correct 9 ms 664 KB Output is correct
82 Correct 9 ms 664 KB Output is correct
83 Correct 9 ms 664 KB Output is correct
84 Correct 9 ms 664 KB Output is correct
85 Correct 12 ms 664 KB Output is correct
86 Correct 13 ms 664 KB Output is correct
87 Correct 15 ms 664 KB Output is correct
88 Correct 12 ms 668 KB Output is correct
89 Correct 9 ms 916 KB Output is correct
90 Correct 8 ms 664 KB Output is correct
91 Correct 9 ms 664 KB Output is correct
92 Correct 10 ms 664 KB Output is correct
93 Correct 11 ms 664 KB Output is correct
94 Correct 9 ms 664 KB Output is correct
95 Correct 7 ms 664 KB Output is correct
96 Correct 10 ms 664 KB Output is correct
97 Correct 8 ms 664 KB Output is correct
98 Correct 8 ms 664 KB Output is correct
99 Correct 9 ms 664 KB Output is correct
100 Correct 9 ms 664 KB Output is correct
101 Correct 12 ms 756 KB Output is correct
102 Correct 9 ms 752 KB Output is correct
103 Correct 9 ms 744 KB Output is correct
104 Correct 10 ms 664 KB Output is correct
105 Correct 13 ms 664 KB Output is correct
106 Correct 15 ms 664 KB Output is correct
107 Correct 10 ms 664 KB Output is correct
108 Correct 8 ms 664 KB Output is correct
109 Correct 12 ms 664 KB Output is correct
110 Correct 10 ms 664 KB Output is correct
111 Correct 8 ms 664 KB Output is correct
112 Correct 13 ms 664 KB Output is correct
113 Correct 10 ms 664 KB Output is correct
114 Correct 10 ms 664 KB Output is correct
115 Correct 11 ms 664 KB Output is correct
116 Correct 9 ms 664 KB Output is correct
117 Correct 9 ms 664 KB Output is correct
118 Correct 12 ms 1004 KB Output is correct
119 Correct 8 ms 664 KB Output is correct
120 Correct 340 ms 980 KB Output is correct
121 Correct 346 ms 1232 KB Output is correct
122 Correct 337 ms 1212 KB Output is correct
123 Correct 299 ms 1232 KB Output is correct
124 Correct 406 ms 1464 KB Output is correct
125 Correct 344 ms 1392 KB Output is correct
126 Correct 326 ms 1180 KB Output is correct
127 Correct 323 ms 1240 KB Output is correct
128 Correct 323 ms 1672 KB Output is correct
129 Correct 351 ms 1356 KB Output is correct
130 Correct 349 ms 1248 KB Output is correct
131 Correct 296 ms 816 KB Output is correct
132 Correct 317 ms 1184 KB Output is correct
133 Correct 567 ms 924 KB Output is correct
134 Correct 304 ms 912 KB Output is correct
135 Correct 320 ms 1056 KB Output is correct
136 Correct 356 ms 816 KB Output is correct
137 Correct 331 ms 892 KB Output is correct
138 Correct 304 ms 1188 KB Output is correct
139 Correct 297 ms 1280 KB Output is correct
140 Correct 331 ms 1012 KB Output is correct
141 Correct 297 ms 1288 KB Output is correct
142 Correct 315 ms 1676 KB Output is correct
143 Correct 310 ms 1348 KB Output is correct
144 Correct 310 ms 1180 KB Output is correct
145 Correct 303 ms 1208 KB Output is correct
146 Correct 344 ms 1040 KB Output is correct
147 Correct 343 ms 1300 KB Output is correct
148 Correct 399 ms 1192 KB Output is correct
149 Correct 330 ms 984 KB Output is correct
150 Correct 351 ms 820 KB Output is correct
151 Correct 385 ms 1052 KB Output is correct
152 Correct 353 ms 1032 KB Output is correct
153 Correct 357 ms 1108 KB Output is correct
154 Correct 385 ms 968 KB Output is correct
155 Correct 382 ms 1144 KB Output is correct
156 Correct 328 ms 1180 KB Output is correct
157 Correct 367 ms 1256 KB Output is correct
158 Correct 440 ms 1028 KB Output is correct
159 Correct 458 ms 1148 KB Output is correct
160 Correct 362 ms 1460 KB Output is correct
161 Correct 405 ms 1120 KB Output is correct
162 Correct 374 ms 1080 KB Output is correct
163 Correct 342 ms 824 KB Output is correct
164 Correct 520 ms 988 KB Output is correct
165 Correct 413 ms 816 KB Output is correct
166 Correct 364 ms 828 KB Output is correct
167 Correct 392 ms 1028 KB Output is correct
168 Correct 511 ms 1148 KB Output is correct
169 Correct 446 ms 1120 KB Output is correct
170 Correct 522 ms 1276 KB Output is correct
171 Correct 537 ms 1396 KB Output is correct
172 Correct 357 ms 1180 KB Output is correct
173 Correct 368 ms 988 KB Output is correct
174 Correct 396 ms 1016 KB Output is correct
175 Correct 517 ms 904 KB Output is correct
176 Correct 374 ms 828 KB Output is correct
177 Correct 428 ms 944 KB Output is correct
178 Correct 401 ms 828 KB Output is correct
179 Correct 397 ms 896 KB Output is correct
180 Correct 455 ms 1124 KB Output is correct
181 Correct 330 ms 1000 KB Output is correct
182 Correct 403 ms 1248 KB Output is correct
183 Correct 324 ms 1196 KB Output is correct
184 Correct 345 ms 1076 KB Output is correct
185 Correct 354 ms 1068 KB Output is correct
186 Correct 335 ms 1284 KB Output is correct
187 Correct 322 ms 1676 KB Output is correct
188 Correct 360 ms 1060 KB Output is correct
189 Correct 366 ms 924 KB Output is correct
190 Correct 450 ms 1040 KB Output is correct
191 Correct 428 ms 1308 KB Output is correct
192 Correct 335 ms 1428 KB Output is correct
193 Correct 332 ms 1044 KB Output is correct
194 Correct 329 ms 1032 KB Output is correct
195 Correct 331 ms 892 KB Output is correct
196 Correct 359 ms 1224 KB Output is correct
197 Correct 315 ms 944 KB Output is correct
198 Correct 316 ms 1100 KB Output is correct
199 Correct 331 ms 1220 KB Output is correct
200 Correct 422 ms 1040 KB Output is correct
201 Correct 477 ms 1108 KB Output is correct
202 Correct 519 ms 1400 KB Output is correct
203 Correct 335 ms 1440 KB Output is correct
204 Correct 333 ms 1756 KB Output is correct
205 Correct 347 ms 844 KB Output is correct
206 Correct 325 ms 1228 KB Output is correct
207 Correct 406 ms 1008 KB Output is correct
208 Correct 319 ms 1156 KB Output is correct
209 Correct 494 ms 988 KB Output is correct
210 Correct 238 ms 1128 KB Output is correct
211 Correct 242 ms 832 KB Output is correct
212 Correct 337 ms 1160 KB Output is correct
213 Correct 264 ms 884 KB Output is correct
214 Correct 257 ms 944 KB Output is correct
215 Correct 250 ms 1420 KB Output is correct
216 Correct 254 ms 1400 KB Output is correct
217 Correct 241 ms 1196 KB Output is correct
218 Correct 344 ms 1268 KB Output is correct
219 Correct 232 ms 848 KB Output is correct
220 Correct 225 ms 836 KB Output is correct
221 Correct 238 ms 1116 KB Output is correct
222 Correct 240 ms 1128 KB Output is correct
223 Correct 318 ms 1276 KB Output is correct
224 Correct 315 ms 872 KB Output is correct
225 Correct 337 ms 1408 KB Output is correct
226 Correct 251 ms 1100 KB Output is correct