Submission #1132873

#TimeUsernameProblemLanguageResultExecution timeMemory
1132873jamjanekNavigation 2 (JOI21_navigation2)C++20
100 / 100
370 ms932 KiB
#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;

namespace {

map<pair<int,int>,int>mapa;

int Function(int x, int y, int r, int c) {
	if(c > y+1)return 10;
	if(c < y-1)return 13;
	if(r > x+1)return 12;
	if(r < x-1)return 11;
	x = x-r+1;
	y = y-c+1;
	return mapa[{x,y}]+1;
}

int tab[110][110];

set<int>wartosci(int n, int k, vector<int>&r, vector<int>&c, int a, int b){
	set<int>ans;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			tab[i][j] = 0;
			
			int r1 = (i-(a-2)+3)%3, r2 = (j-(b-2)+3)%3, reszta;
			reszta = mapa[{r1, r2}];
			if(reszta == 8){
				tab[i][j] = 14;
			}
			else if(reszta == 7){
				tab[i][j] = 0;
			}
			else{
				tab[i][j] = Function(i, j, r[reszta], c[reszta]);
			}
			ans.insert(tab[i][j]);
		}
	}
	return ans;
}

} // namespace

void Anna(int n, int k, std::vector<int> r, std::vector<int> c) {
	mapa[{0,0}] = 0;
	mapa[{0,1}] = 1;
	mapa[{0,2}] = 2;
	mapa[{1,0}] = 3;
	mapa[{1,1}] = 4;
	mapa[{1,2}] = 5;
	mapa[{2,0}] = 6;
	mapa[{2,1}] = 7;
	mapa[{2,2}] = 8;
	set<int>values;
	bool czy = 0;
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			czy = 1;
			values = wartosci(n, k, r, c, i, j);
			if(values.find(9)!=values.end())
				czy = 0;
	//		if(czy)cerr<<i<<" "<<j<<"\n";
			if(czy)break;
		}
		if(czy)break;
	}
	int val;
	for(val=1;val<=8;val++){
		if(values.find(val)==values.end())
			break;
	}
	/*
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++)
			printf("%d ", tab[i][j]);
		printf("\n");
	}
	printf("%d\n", val);
	*/
	
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(tab[i][j]>9)tab[i][j]--;
			if(tab[i][j] == 0)
				tab[i][j] = val;
			if(tab[i][j]>val)tab[i][j]--;
	//		printf("%d ", tab[i][j]);
		}
	//	printf("\n");
	}
	
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			SetFlag(i, j, tab[i][j]);
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;


std::vector<int> Bruno(int k, std::vector<int> value) {
	vector<vector<int>>values(3);
	for(int i=0;i<9;i++)
		values[i/3].push_back(value[i]);
	int a, b;
	for(a=0;a<3;a++){
		for(b=0;b<3;b++)
			if(values[a][b] == 12)break;
		if(b<3 && values[a][b] == 12)break;
	}
	int val = values[a][(b-1+3)%3];

	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			if(values[i][j]>=val)values[i][j]++;
			if(values[i][j]>=9)values[i][j]++;
		}
	}
	
	std::vector<int> res(k, 0);
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			if(i*3+j<7){
				int x = (a+1+i)%3, y = (b+1+j)%3;
				int pom = values[x][y];
				if(pom==10)
					pom = 0;
				else if(pom == 11)
					pom = 3;
				else if(pom == 12)
					pom = 2;
				else if(pom == 13)
					pom = 1;
				else if(pom == 1){
					if(x>0)pom = 2;
					else if(y == 0)pom = 4;
					else pom = 0;
				}
				else if(pom == 2){
					if(x>0)pom = 2;
					else if(y == 1)pom = 4;
					else if(y == 0)pom = 1;
					else if(y == 2)pom = 0;
				}
				else if(pom == 3){
					if(x>0)pom = 2;
					else if(y == 2)pom = 4;
					else pom = 1;
				}
				else if(pom == 4){
					if(y>0)pom = 0;
					else if(x == 1)pom = 4;
					else if(x == 0)pom = 3;
					else if(x == 2)pom = 2;
				}
				else if(pom == 5){
					if(y == 0)pom = 1;
					else if(y == 2)pom = 0;
					else if(x == 0)pom = 3;
					else if(x == 2)pom = 2;
					else pom = 4;
				}
				else if(pom == 6){
					if(y<2)pom = 1;
					else if(x == 1)pom = 4;
					else if(x == 0)pom = 3;
					else if(x == 2)pom = 2;					
				}
				else if(pom == 7){
					if(x<2)pom = 3;
					else if(y == 0)pom = 4;
					else pom = 0;
				}
				else if(pom == 8){
					if(x<2)pom = 3;
					else if(y == 1)pom = 4;
					else if(y == 0)pom = 1;
					else if(y == 2)pom = 0;
				}
				else if(pom == 9){
					if(x<2)pom = 3;
					else if(y == 2)pom = 4;
					else pom = 1;					
				}
				res[i*3+j] = pom;
			}
		}
	}
	return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...