Submission #951571

# Submission time Handle Problem Language Result Execution time Memory
951571 2024-03-22T06:48:00 Z GrindMachine Navigation 2 (JOI21_navigation2) C++17
85 / 100
563 ms 2400 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)

template<typename T>
void amin(T &a, T b) {
    a = min(a,b);
}

template<typename T>
void amax(T &a, T b) {
    a = max(a,b);
}

#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif

/*

refs:
edi
https://codeforces.com/blog/entry/88748?#comment-774016 (this thread)

*/

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;

#include "Anna.h"

void Anna(int n, int k, std::vector<int> R, std::vector<int> C) {
    int a[n][n];
    rep(i,n) rep(j,n) a[i][j] = 1;

    vector<bool> used(10);

    rep(i,n){
        rep(j,n){
            int ind = (i%3)*3+(j%3);
            if(!ind){
                a[i][j] = 14;
            }
            else{
                if(ind <= k){
                    int r = R[ind-1], c = C[ind-1];
                    int d = max(abs(i-r),abs(j-c));
                    if(d > 1){
                        // (i,j+1)
                        if(j+2 <= c){
                            a[i][j] = 10;
                        }
                        // (i,j-1)
                        else if(j-2 >= c){
                            a[i][j] = 11;
                        }
                        // (i+1,j)
                        else if(i+2 <= r){
                            a[i][j] = 12;
                        }
                        // (i-1,j)
                        else if(i-2 >= r){
                            a[i][j] = 13;
                        }
                        else{
                            assert(0);
                        }
                    }
                    else{
                        int d1 = i-r+1, d2 = j-c+1;
                        a[i][j] = (d1*3)+d2+1;
                        used[a[i][j]] = 1;
                    }
                }
            }
        }
    }

    int unused = -1;
    rep1(i,9){
        if(!used[i]){
            unused = i;
            break;
        }
    }

    assert(unused != -1);
    assert(unused <= 8);

    rep(i,n){
        rep(j,n){
            int ind = (i%3)*3+(j%3);
            if(ind == 8){
                a[i][j] = unused;
            }
            else{
                if(a[i][j] > unused){
                    a[i][j]--;
                }
            }
        }
    }

    rep(i,n){
        rep(j,n){
            SetFlag(i,j,a[i][j]);
        }
    }
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)

template<typename T>
void amin(T &a, T b) {
    a = min(a,b);
}

template<typename T>
void amax(T &a, T b) {
    a = max(a,b);
}

#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif

/*

refs:
edi
https://codeforces.com/blog/entry/88748?#comment-774016 (this thread)

*/

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;

#include "Bruno.h"

std::vector<int> Bruno(int k, std::vector<int> values) {
    int a[3][3];
    memset(a,0,sizeof a);
    rep(i,sz(values)){
        a[i/3][i%3] = values[i];
    }

    int zi = -1, zj = -1;
    rep(i,3){
        rep(j,3){
            if(a[i][j] == 13){
                assert(zi == -1);
                zi = i, zj = j;
            } 
        }
    }

    assert(zi != -1);

    int label[3][3];
    label[zi][zj] = 0;

    rep1(iter,8){
        if(iter%3 == 0){
            zi = (zi+1)%3;
        }
        zj = (zj+1)%3;
        label[zi][zj] = iter;
    }

    int unused = a[zi][zj];
    rep(i,3){
        rep(j,3){
            if(a[i][j] >= unused){
                a[i][j]++;
            }
        }
    }

    vector<int> di = {0,0,1,-1,0};
    vector<int> dj = {1,-1,0,0,0};

    vector<int> ans(k);
    rep(i,3){
        rep(j,3){
            int ind = label[i][j];
            if(!ind or ind > k) conts;

            ind--;
            pii cell = {-1,-1};

            if(a[i][j] > 9){
                int x = a[i][j]-10;
                ans[ind] = x;
                conts;
            }
            else{
                int v = a[i][j]-1;
                cell = {i,j};
                auto &[r,c] = cell;

                if(v == 0){
                    r++, c++;
                }
                if(v == 1){
                    r++;
                }
                if(v == 2){
                    r++, c--;
                }
                if(v == 3){
                    c++;
                }
                if(v == 4){

                }
                if(v == 5){
                    c--;
                }
                if(v == 6){
                    r--, c++;
                }
                if(v == 7){
                    r--;
                }
                if(v == 8){
                    r--, c--;
                }
            }

            auto [r,c] = cell;
            int dir = 4;

            // (i,j+1)
            if(1 < c){
                dir = 0;
            }
            // (i,j-1)
            else if(1 > c){
                dir = 1;
            }
            // (i+1,j)
            else if(1 < r){
                dir = 2;
            }
            else if(1 > r){
                dir = 3;
            }

            ans[ind] = dir;
        }
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Partially correct 10 ms 664 KB Partially correct
2 Partially correct 8 ms 664 KB Partially correct
3 Partially correct 7 ms 920 KB Partially correct
4 Partially correct 8 ms 920 KB Partially correct
5 Partially correct 9 ms 920 KB Partially correct
6 Partially correct 9 ms 920 KB Partially correct
7 Partially correct 9 ms 664 KB Partially correct
8 Partially correct 8 ms 664 KB Partially correct
9 Partially correct 10 ms 664 KB Partially correct
10 Partially correct 9 ms 920 KB Partially correct
11 Partially correct 7 ms 748 KB Partially correct
12 Partially correct 9 ms 920 KB Partially correct
13 Partially correct 8 ms 920 KB Partially correct
14 Partially correct 9 ms 920 KB Partially correct
15 Partially correct 9 ms 672 KB Partially correct
16 Partially correct 11 ms 920 KB Partially correct
17 Partially correct 10 ms 664 KB Partially correct
18 Partially correct 10 ms 920 KB Partially correct
19 Partially correct 8 ms 920 KB Partially correct
20 Partially correct 7 ms 664 KB Partially correct
21 Partially correct 8 ms 664 KB Partially correct
22 Partially correct 8 ms 664 KB Partially correct
23 Partially correct 9 ms 664 KB Partially correct
24 Partially correct 9 ms 836 KB Partially correct
25 Partially correct 9 ms 920 KB Partially correct
26 Partially correct 9 ms 920 KB Partially correct
27 Partially correct 7 ms 664 KB Partially correct
28 Partially correct 8 ms 920 KB Partially correct
29 Partially correct 9 ms 920 KB Partially correct
30 Partially correct 8 ms 664 KB Partially correct
31 Partially correct 9 ms 664 KB Partially correct
32 Partially correct 8 ms 664 KB Partially correct
33 Partially correct 7 ms 688 KB Partially correct
34 Partially correct 9 ms 944 KB Partially correct
35 Partially correct 9 ms 688 KB Partially correct
36 Partially correct 9 ms 688 KB Partially correct
37 Partially correct 8 ms 688 KB Partially correct
38 Partially correct 10 ms 944 KB Partially correct
39 Partially correct 9 ms 688 KB Partially correct
40 Partially correct 10 ms 940 KB Partially correct
41 Partially correct 9 ms 688 KB Partially correct
42 Partially correct 11 ms 944 KB Partially correct
43 Partially correct 10 ms 688 KB Partially correct
44 Partially correct 10 ms 664 KB Partially correct
45 Partially correct 9 ms 920 KB Partially correct
46 Partially correct 10 ms 664 KB Partially correct
47 Partially correct 10 ms 920 KB Partially correct
48 Partially correct 10 ms 664 KB Partially correct
49 Partially correct 12 ms 920 KB Partially correct
50 Partially correct 10 ms 748 KB Partially correct
51 Partially correct 11 ms 664 KB Partially correct
52 Partially correct 12 ms 664 KB Partially correct
53 Partially correct 13 ms 916 KB Partially correct
54 Partially correct 10 ms 664 KB Partially correct
55 Partially correct 10 ms 664 KB Partially correct
56 Partially correct 11 ms 664 KB Partially correct
57 Partially correct 12 ms 664 KB Partially correct
58 Partially correct 12 ms 940 KB Partially correct
59 Partially correct 13 ms 920 KB Partially correct
60 Partially correct 10 ms 664 KB Partially correct
61 Partially correct 13 ms 664 KB Partially correct
62 Partially correct 13 ms 920 KB Partially correct
63 Partially correct 12 ms 920 KB Partially correct
64 Partially correct 11 ms 664 KB Partially correct
65 Partially correct 11 ms 920 KB Partially correct
66 Partially correct 11 ms 920 KB Partially correct
67 Partially correct 10 ms 920 KB Partially correct
68 Partially correct 10 ms 920 KB Partially correct
69 Partially correct 11 ms 664 KB Partially correct
70 Partially correct 12 ms 664 KB Partially correct
71 Partially correct 13 ms 920 KB Partially correct
72 Partially correct 12 ms 1172 KB Partially correct
73 Partially correct 11 ms 920 KB Partially correct
74 Partially correct 12 ms 920 KB Partially correct
75 Partially correct 12 ms 920 KB Partially correct
76 Partially correct 12 ms 664 KB Partially correct
77 Partially correct 13 ms 920 KB Partially correct
78 Partially correct 10 ms 920 KB Partially correct
79 Partially correct 11 ms 920 KB Partially correct
80 Partially correct 11 ms 664 KB Partially correct
81 Partially correct 11 ms 664 KB Partially correct
82 Partially correct 13 ms 664 KB Partially correct
83 Partially correct 13 ms 664 KB Partially correct
84 Partially correct 10 ms 664 KB Partially correct
85 Partially correct 10 ms 664 KB Partially correct
86 Partially correct 12 ms 920 KB Partially correct
87 Partially correct 13 ms 920 KB Partially correct
88 Partially correct 13 ms 664 KB Partially correct
89 Partially correct 13 ms 1172 KB Partially correct
90 Partially correct 11 ms 664 KB Partially correct
91 Partially correct 13 ms 920 KB Partially correct
92 Partially correct 12 ms 664 KB Partially correct
93 Partially correct 12 ms 664 KB Partially correct
94 Partially correct 13 ms 752 KB Partially correct
95 Partially correct 11 ms 748 KB Partially correct
96 Partially correct 12 ms 664 KB Partially correct
97 Partially correct 15 ms 664 KB Partially correct
98 Partially correct 11 ms 920 KB Partially correct
99 Partially correct 12 ms 920 KB Partially correct
100 Partially correct 12 ms 920 KB Partially correct
101 Partially correct 10 ms 920 KB Partially correct
102 Partially correct 12 ms 748 KB Partially correct
103 Partially correct 12 ms 664 KB Partially correct
104 Partially correct 12 ms 664 KB Partially correct
105 Partially correct 12 ms 920 KB Partially correct
106 Partially correct 13 ms 748 KB Partially correct
107 Partially correct 13 ms 752 KB Partially correct
108 Partially correct 10 ms 920 KB Partially correct
109 Partially correct 11 ms 920 KB Partially correct
110 Partially correct 13 ms 920 KB Partially correct
111 Partially correct 11 ms 664 KB Partially correct
112 Partially correct 11 ms 920 KB Partially correct
113 Partially correct 12 ms 1108 KB Partially correct
114 Partially correct 12 ms 920 KB Partially correct
115 Partially correct 13 ms 920 KB Partially correct
116 Partially correct 13 ms 664 KB Partially correct
117 Partially correct 13 ms 664 KB Partially correct
118 Partially correct 12 ms 664 KB Partially correct
119 Partially correct 15 ms 920 KB Partially correct
120 Partially correct 516 ms 1960 KB Partially correct
121 Partially correct 486 ms 1864 KB Partially correct
122 Partially correct 464 ms 2252 KB Partially correct
123 Partially correct 453 ms 1736 KB Partially correct
124 Partially correct 478 ms 1924 KB Partially correct
125 Partially correct 474 ms 1784 KB Partially correct
126 Partially correct 490 ms 1832 KB Partially correct
127 Partially correct 474 ms 2320 KB Partially correct
128 Partially correct 511 ms 1632 KB Partially correct
129 Partially correct 466 ms 2216 KB Partially correct
130 Partially correct 456 ms 1676 KB Partially correct
131 Partially correct 535 ms 1980 KB Partially correct
132 Partially correct 472 ms 2400 KB Partially correct
133 Partially correct 462 ms 1816 KB Partially correct
134 Partially correct 496 ms 1908 KB Partially correct
135 Partially correct 470 ms 1556 KB Partially correct
136 Partially correct 465 ms 1680 KB Partially correct
137 Partially correct 489 ms 1632 KB Partially correct
138 Partially correct 447 ms 1440 KB Partially correct
139 Partially correct 458 ms 1880 KB Partially correct
140 Partially correct 509 ms 1592 KB Partially correct
141 Partially correct 478 ms 1668 KB Partially correct
142 Partially correct 504 ms 1892 KB Partially correct
143 Partially correct 489 ms 2212 KB Partially correct
144 Partially correct 453 ms 2144 KB Partially correct
145 Partially correct 460 ms 2108 KB Partially correct
146 Partially correct 501 ms 1420 KB Partially correct
147 Partially correct 463 ms 2000 KB Partially correct
148 Partially correct 493 ms 1924 KB Partially correct
149 Partially correct 477 ms 1820 KB Partially correct
150 Partially correct 458 ms 1492 KB Partially correct
151 Partially correct 458 ms 2056 KB Partially correct
152 Partially correct 463 ms 1936 KB Partially correct
153 Partially correct 479 ms 1976 KB Partially correct
154 Partially correct 460 ms 2168 KB Partially correct
155 Partially correct 477 ms 1588 KB Partially correct
156 Partially correct 497 ms 1724 KB Partially correct
157 Partially correct 465 ms 1544 KB Partially correct
158 Partially correct 472 ms 1828 KB Partially correct
159 Partially correct 493 ms 1864 KB Partially correct
160 Partially correct 460 ms 1716 KB Partially correct
161 Partially correct 541 ms 1892 KB Partially correct
162 Partially correct 498 ms 1880 KB Partially correct
163 Partially correct 528 ms 1848 KB Partially correct
164 Partially correct 527 ms 1948 KB Partially correct
165 Partially correct 488 ms 1660 KB Partially correct
166 Partially correct 516 ms 1408 KB Partially correct
167 Partially correct 535 ms 1768 KB Partially correct
168 Partially correct 529 ms 1512 KB Partially correct
169 Partially correct 525 ms 2080 KB Partially correct
170 Partially correct 466 ms 2256 KB Partially correct
171 Partially correct 485 ms 2008 KB Partially correct
172 Partially correct 455 ms 1888 KB Partially correct
173 Partially correct 476 ms 2196 KB Partially correct
174 Partially correct 453 ms 1784 KB Partially correct
175 Partially correct 478 ms 1732 KB Partially correct
176 Partially correct 465 ms 1872 KB Partially correct
177 Partially correct 469 ms 2060 KB Partially correct
178 Partially correct 563 ms 1428 KB Partially correct
179 Partially correct 488 ms 1668 KB Partially correct
180 Partially correct 474 ms 2060 KB Partially correct
181 Partially correct 524 ms 1588 KB Partially correct
182 Partially correct 484 ms 1780 KB Partially correct
183 Partially correct 461 ms 1412 KB Partially correct
184 Partially correct 475 ms 1768 KB Partially correct
185 Partially correct 482 ms 1732 KB Partially correct
186 Partially correct 501 ms 1676 KB Partially correct
187 Partially correct 514 ms 1688 KB Partially correct
188 Partially correct 506 ms 2024 KB Partially correct
189 Partially correct 469 ms 2068 KB Partially correct
190 Partially correct 533 ms 1740 KB Partially correct
191 Partially correct 525 ms 2188 KB Partially correct
192 Partially correct 488 ms 1644 KB Partially correct
193 Partially correct 507 ms 2260 KB Partially correct
194 Partially correct 452 ms 1892 KB Partially correct
195 Partially correct 494 ms 1940 KB Partially correct
196 Partially correct 476 ms 2144 KB Partially correct
197 Partially correct 470 ms 2376 KB Partially correct
198 Partially correct 469 ms 1548 KB Partially correct
199 Partially correct 461 ms 2148 KB Partially correct
200 Partially correct 470 ms 1936 KB Partially correct
201 Partially correct 462 ms 1988 KB Partially correct
202 Partially correct 490 ms 2212 KB Partially correct
203 Partially correct 473 ms 1672 KB Partially correct
204 Partially correct 492 ms 2116 KB Partially correct
205 Partially correct 456 ms 2328 KB Partially correct
206 Partially correct 489 ms 1792 KB Partially correct
207 Partially correct 507 ms 2128 KB Partially correct
208 Partially correct 458 ms 2112 KB Partially correct
209 Partially correct 536 ms 1716 KB Partially correct
210 Partially correct 359 ms 1420 KB Partially correct
211 Partially correct 379 ms 1784 KB Partially correct
212 Partially correct 343 ms 2100 KB Partially correct
213 Partially correct 373 ms 2244 KB Partially correct
214 Partially correct 364 ms 1572 KB Partially correct
215 Partially correct 391 ms 1916 KB Partially correct
216 Partially correct 411 ms 1848 KB Partially correct
217 Partially correct 374 ms 1792 KB Partially correct
218 Partially correct 368 ms 1780 KB Partially correct
219 Partially correct 364 ms 2048 KB Partially correct
220 Partially correct 360 ms 1836 KB Partially correct
221 Partially correct 358 ms 1660 KB Partially correct
222 Partially correct 369 ms 1572 KB Partially correct
223 Partially correct 348 ms 1752 KB Partially correct
224 Partially correct 361 ms 1776 KB Partially correct
225 Partially correct 394 ms 1660 KB Partially correct
226 Partially correct 352 ms 1860 KB Partially correct