제출 #1354510

#제출 시각아이디문제언어결과실행 시간메모리
1354510WH8Casino (JOI26_casino)C++17
32 / 100
223 ms852 KiB
#include "Azzurro.h"
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;

namespace {
    // グローバル変数と内部関数は無名名前空間内で宣言すること
    // All global variables and internal functions should be declared in an unnamed namespace
    int variable_example = 0;
    int function_example(void) { return 0; }
	int c(char c){
		if(c=='B')return 0;
		else return 1;
	}
}

std::vector<std::vector<int>> Azzurro(int N, int L, std::string S) {
    std::vector<std::vector<int>> x(N, std::vector<int>(N, 0));
	if(L > 16) return x;
	int n=N;
	//cout<<N<<L<<S<<endl;
	//return x;
	int h = n/2;
	vector<pair<int,int>> pos={{0, 0}, {0, n/2}, {n/2, 0}, {n/2, n/2}};
	for(int i=0;i<L;i++){
		int write=c(S[i]);
		for(int j=0;j<4;j++){
			x[pos[j].f+i/h][pos[j].s+i%h]=write;
		}
	}
	/*for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			cout<<x[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;*/

    return x;
}
#include "Bordeaux.h"
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;

namespace {
    // グローバル変数と内部関数は無名名前空間内で宣言すること
    // All global variables and internal functions should be declared in an unnamed namespace
    int variable_example = 0;
    int function_example(void) { return 0; }
	int c(char c){
		if(c=='B')return 0;
		else return 1;
	}
}

vector<pair<int,int>> dir={{0, 1}, {1, 0}, {-1, 0}, {0, -1}}; // R, D
std::string Bordeaux(int N, int L, std::vector<std::vector<int>> T) {
	/*for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			cout<<T[i][j]<<" ";
		}
		cout<<endl;
	}*/
	string random;
	for(int i=0;i<L;i++)random += 'A';
	if(L > 16) return random;
	int n=N;
	int h=n/2;
	vector<pair<int,int>> pos={{0, n/2}, {n/2, 0}};
	int ans=-1;
	for(int j=0;j<2;j++){
		vector<vector<int>> vis(n+1, vector<int>(n+1, 0));
		vector<vector<int>> F(n+1, vector<int>(n+1, 0));
		for(int x=0;x<n;x++){
			for(int y=0;y<n;y++){
				F[x][y]=(T[x][y] != T[pos[j].f+x%h][pos[j].s+y%h]);
				//cout<<F[x][y];
			}
			//cout<<endl;
		}
		bool die=0;
		auto dfs=[&](auto && dfs, int x, int y)->void{
			int deg=0;
			vis[x][y]=1;
			for(auto [dx, dy] : dir){
				int nx=x+dx, ny=y+dy;
				if(nx < 0 or nx >= n or ny < 0 or ny >= n) continue;
				if(vis[nx][ny])continue;
				if(!F[nx][ny]){
					//printf("%d %d rej \n", nx, ny);
					continue;
				}
				deg++;
			}
			//printf("%d %d, deg %d\n", x, y, deg);
			if(deg > 1) {
				die=1;
				return;
			}
			for(auto [dx, dy] : dir){
				int nx=x+dx, ny=y+dy;
				if(nx < 0 or nx >= n or ny < 0 or ny >= n) continue;
				if(vis[nx][ny])continue;
				if(!F[nx][ny])continue;
				vis[nx][ny]=1;
				dfs(dfs, nx, ny);
			}
		};
		dfs(dfs, 0, 0);
		if(!die and vis[n-1][n-1]){
			ans = j;
			break;
		}
	}
	assert(ans != -1);
	string ret;
	for(int i=0;i<L;i++){
		if( T[pos[ans].f+i/h][pos[ans].s+i%h]){
			ret+='A';
		}
		else ret += 'B';
	}
	//cout<<ret<<endl;
	return ret;
}
#Verdict Execution timeMemoryGrader output
Fetching results...