# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1010147 | Unforgettablepl | Navigation 2 (JOI21_navigation2) | C++17 | 567 ms | 1756 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |