답안 #985093

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
985093 2024-05-17T10:34:30 Z Kinoko_Sokora 화성 (APIO22_mars) C++17
0 / 100
0 ms 332 KB
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<stack>
#include<iomanip>
#include<queue>
#include<set>
#include<functional>
#include<tuple>
#include<bitset>
#include<cassert>
#include<cstdint>
#include<complex>
#include<random>
#include<fstream>
#include <unordered_map>  
#include <unordered_set>  
using namespace std;
bool printb(bool f) {
	if (f)printf("Yes\n");
	else printf("No\n");
	return f;
}
template<class T>
void prt(T t = "", string sep = "\n") { cout << t << sep; return; }
template<class T>
void printl(vector<T> a, string sep = " ") {
	for (int i = 0; i < a.size(); i++) {
		cout << a[i];
		if (i != a.size() - 1)cout << sep;
	}
	cout << "\n";
	return;
}

bool prt_isfixed = false;
template<class T>
void prt_fix(T t, string sep = "\n") {
	if (!prt_isfixed) {
		cout << fixed << setprecision(15);
		prt_isfixed = true;
	}
	prt(t, sep);
}
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#pragma GCC target "prefer-vector-width=512"
#pragma GCC optimize "Ofast"
#pragma GCC optimize("unroll-loops")

using uint = unsigned int;
using llong = long long;
using ullong = unsigned long long;
using pii = pair<int, int>;
using pll = pair<llong, llong>;
using pli = pair<llong, int>;
using pil = pair<int, llong>;
template<typename T> using vec2 = vector<vector<T>>;
template<typename T> inline bool chmin(T& a, T b) { return (a > b) ? (a = b, true) : false; }
template<typename T> inline bool chmax(T& a, T b) { return (a < b) ? (a = b, true) : false; }
bool bitIn(llong a, int b) { return ((a >> b) & 1); }
int bitCnt(llong a) {
	int re = 0;
	while (a > 0) {
		if (a & 1)re++;
		a >>= 1;
	}
	return re;
}
llong powL(llong n, llong i) {
	llong re = 1;
	while (i >= 1) {
		if (i & 1) re *= n;
		n *= n;
		i >>= 1;
	}
	return re;
}
llong powL_M(llong n, llong i, llong mod) {
	llong re = 1;
	while (i >= 1) {
		if (i & 1) {
			re *= n;
			re %= mod;
		}
		n *= n;
		n %= mod;
		i >>= 1;
	}
	return re;
}


llong cei(llong a, llong b) {
	if (a % b == 0)return a / b;
	else if (a < 0) {
		return a / b;
	}
	else {
		return a / b + 1;
	}
}

llong flo(llong a, llong b) {
	if (a % b == 0)return a / b;
	else if (a < 0) {
		return a / b - 1;
	}
	else {
		return a / b;
	}
}
int  dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int  dx2[8] = { -1,-1,1,1,-1,-1,1,1 }, dy2[8] = { 1,-1,-1,1,1,-1,-1,1 };
int dx8[8] = { 0,1,1,1,0,-1,-1,-1 }, dy8[8] = { -1,-1,0,1,1,1,0,-1 };
#include "mars.h"


//size付きunionfind 
class unionfind {
private:
	vector<int> parents;
public:
	unionfind(int n) {
		parents.resize(n, -1);
	}
	void initU(int n) {
		parents.assign(n, -1);
	}

	int findset(int n) {
		if (parents[n] >= 0) {
			parents[n] = findset(parents[n]);
			return parents[n];
		}
		return n;
	}

	void unite(int x, int y) {
		x = findset(x);
		y = findset(y);
		if (x == y) {
			return;
		}

		if (parents[x] < parents[y]) swap(x, y);
		//yの方がサイズが大きくなる
		parents[y] += parents[x];
		parents[x] = y;
	}

	bool same(int x, int y) {
		return findset(x) == findset(y);
	}

	int size(int x) {
		return -parents[findset(x)];
	}
};


inline int f(int a, int b, int n) {
	return a * (2 * n + 1) + b;
}

int solve(vector<vector<bool>> ma, int n) {
	unionfind uf(powL(2 * n + 1, 2));
	rep(i, 2 * n + 1) {
		rep(j, 2 * n) {
			if (ma[i][j] && ma[i][j + 1]) {
				uf.unite(f(i, j, n), f(i, j + 1, n));
			}
			if (ma[j][i] && ma[j + 1][i]) {
				uf.unite(f(j, i, n), f(j + 1, i, n));
			}
		}
	}
	set<int> s;
	rep(i, powL(2 * n + 1, 2)) {
		if (!ma[i / (2 * n + 1)][i % (2 * n + 1)])continue;
		s.insert(uf.findset(i));
	}
	return int(s.size());
}

std::string process(std::vector <std::vector<std::string>> a, int x, int y, int k, int n) {
	assert(n <= 8);
	if (n == 1) {
		vector<vector<bool>> ma(3, vector<bool>(3, false));
		rep(ii, 3) {
			rep(jj, 3) {
				if (a[ii][jj][0] == '1') {
					ma[ii][jj] = true;
				}
			}
		}
		int re = solve(ma, n);
		string ans = "";
		rep(ii, 10) {
			if ((re >> ii) & 1)ans += '1';
			else ans += '0';
		}
		rep(ii, 90)ans += '0';
		return ans;
	}

	if (k == 0) {
		int pos = 0;
		if (x % 2 == 1)pos++;
		if (y % 2 == 1)pos += 2;

		string ans = "";
		rep(i, 100)ans += '0';
		rep(i, 3) {
			rep(j, 3) {
				if (100 * pos <= f(x + i, y + j, n) && f(x + i, y + j, n) < 100 * pos + 100) {
					if (a[i][j][0] == '0')continue;
					ans[f(x + i, y + j, n) - 100 * pos] = '1';
				}
			}
		}
		return ans;
	}

	string ans = "";
	rep(i, 100)ans += '0';
	rep(i, 2) {
		rep(j, 2) {
			rep(l, 100) {
				if (a[2 * i][2 * j][l] == '1')ans[l] = '1';
			}
		}
	}


	if (k != n - 1) {	
		return ans;
	}
	a[0][0] = ans;
	vector<vector<bool>> ma(2 * n + 1, vector<bool>(2 * n + 1, false));
	rep(i, 2 * n + 1) {
		rep(j, 2 * n + 1) {
			int cn = f(i, j, n);
			rep(l, 4) {
				if (100 * l <= cn && cn < 100 * l + 100) {
					if (a[l % 2][l / 2][cn - 100 * l] == '1') {
						ma[i][j] = true;
					}
				}
			}
		}
	}
	rep(ii, 2)rep(jj, 2) {
		prt(a[ii][jj]);
	}
	/*for (auto i : ma)printl(i);
	prt(re);*/
	int re = solve(ma, n);
	ans = "";
	rep(ii, 10) {
		if ((re >> ii) & 1)ans += '1';
		else ans += '0';
	}
	rep(ii, 90)ans += '0';
	return ans;
}

/*
int main() {
	int n;
	cin >> n;
	string sta = "";
	rep(i, 100)sta += '0';
	vec2<string> st(2 * n + 1, vector<string>(2 * n + 1, sta));
	sta[0] = '1';
	rep(i, 2 * n + 1) {
		string s;
	//	cin >> s;
		rep(j, 2 * n + 1) {
			//if (s[j] == '1')
				st[i][j] = sta;
		}
	}
	rep(i, n) {
		int m = 2 * (n - i - 1);
		rep(ii, m + 1) {
			rep(jj, m + 1) {
				vector<vector<string>> a(3, vector<string>(3));
				rep(l, 3)rep(o, 3)a[l][o] = st[ii + l][jj + o];
				st[ii][jj] = process(a, ii, jj, i, n);
			}
		}
		if (i==0) {
			rep(ii, 2 * n + 1) {
				rep(jj, 2 * n + 1) {
					prt(st[ii][jj]);
				}
				prt("");
			}
			prt("");
			prt("-------------------------------------------------");
			prt("");
		}
	}
	prt(st[0][0]);
}
//*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Security violation, do not print anything to stdio
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Security violation, do not print anything to stdio
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Security violation, do not print anything to stdio
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Security violation, do not print anything to stdio
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Security violation, do not print anything to stdio
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Security violation, do not print anything to stdio
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Security violation, do not print anything to stdio
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Security violation, do not print anything to stdio
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Security violation, do not print anything to stdio
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Security violation, do not print anything to stdio
2 Halted 0 ms 0 KB -