답안 #315186

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
315186 2020-10-22T04:13:51 Z Kevin_Zhang_TW Costinland (info1cup19_costinland) C++17
71.589 / 100
1 ms 336 KB
#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void debug(auto L, auto R) { while (L < R) cerr << *L << " \n"[L+1==R], ++L; }
void kout(){ cerr << endl; }
template<class T1, class ...T2> void kout(T1 a, T2 ...e) { cerr << a << ' ', kout(e...); }
#else
#define DE(...) 0
#define deubg(...) 0
#endif
const int MAX_N = 111, wid1 = 4;
const ll inf = 1e18 + 10;
ll K;
char w[MAX_N][MAX_N];
ll way[MAX_N][MAX_N][2];
void add(ll &v, ll val) {
	v = min(inf, v + val);
}
ll check1() {
	memset(way, 0, sizeof(way));
	way[1][1][0] = 1;
	for (int i = 1;i <= wid1;++i)
		for (int j = 1;j <= wid1;++j) {
			ll sum = way[i][j][0] + way[i][j][1];
			if (sum > K) return false;
			if (w[i][j] == 'X') {
				add(way[i+1][j][0], sum);
				add(way[i][j+1][1], sum);
			}
			if (w[i][j] == 'r') 
				add(way[i][j+1][1], sum);
			if (w[i][j] == 'd')
				add(way[i+1][j][0], sum);
			if (w[i][j] == '.') {
				add(way[i+1][j][0], way[i][j][0]);
				add(way[i][j+1][1], way[i][j][1]);
			}
		}
	//DE(way[wid1][wid1][0] + way[wid1][wid1][1], K);
	return way[wid1][wid1][0] + way[wid1][wid1][1];
}
bool dfs(int x, int y) {
	if (x == wid1 && y == wid1) 
		return w[x][y] = '.', check1();
	if (y > wid1)
		return dfs(x+1, 1);
	for (char s : {'r', 'd', 'X', '.'}) {
		if (x == 1 && y == 1 && s == '.') continue;
		if (y == wid1 && s == 'r') continue;
		if (x == wid1 && s == 'd') continue;
		w[x][y] = s;
		if (dfs(x, y+1))
			return true;
	}
	return false;
}
void subtask1() {
	assert(dfs(0,0));
	cout << wid1 << ' ' << wid1 << '\n';
	for (int i = 1;i <= wid1;++i)
		cout << w[i]+1 << '\n';
}
void special(ll K) {
	if (K == 2) {
		cout << "2 2\nxd\nr.\n";
		return;
	}
	int lev = 3;
	int n = lev + 2;
	for (int i = 1;i <= n;++i)
		for (int j = 1;j <= n;++j)
			w[i][j] = '.';

	for (int i = 1;i <= n;++i)
		w[i][n] = 'd', w[n][i] = 'r';

	w[1][1] = 'X';
	w[n][n] = '.';
	
	K -= 2;

	for (int i = 2;i < n;++i) {
		w[i][i] = 'X';
		w[i][i+1] = 'd';
		w[i+1][i] = 'r';
	}

	for (ll i = 2, v = 1ll<<lev;i < n;++i, v>>=1) {
		if (K & (v<<1)) {
			w[1][i] = w[i][1] = 'X';
			K ^= v<<1;
		}
		else if (K & v) {
			w[1][i] = 'X', K ^= v;
		}
	}

	DE(K);	
	if (K) {
		assert(K == 1);
		w[n-1][1] = 'X';
		w[n-1][2] = 'd';
	}

	cout << n << ' ' << n << '\n';
	for (int i = 1;i <= n;++i)
		cout << w[i]+1 << '\n';
}

void logone(ll K) {
	int lev = __lg(--K);
	int n = lev + 2;
	for (int i = 1;i <= n;++i)
		for (int j = 1;j <= n;++j)
			w[i][j] = '.';

	for (int i = 1;i <= n;++i)
		w[i][n] = 'd', w[n][i] = 'r';

	w[1][1] = 'r';
	w[n][n] = '.';

	for (int i = 2;i < n;++i) {
		w[i][i] = 'X';
		w[i][i+1] = 'd';
		w[i+1][i] = 'r';
	}
	for (ll i = 2, v = 1ll<<lev;i < n;++i, v>>=1) {
		if (K & v) w[1][i] = 'X';
		else w[1][i] = 'r';
	}
	if (K&1) w[1][1] = 'X';

	cout << n << ' ' << n << '\n';
	for (int i = 1;i <= n;++i)
		cout << w[i]+1 << '\n';
	DE(check1());
}
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> K;
	if (K <= 19)
		special(K);
	else
		logone(K);
}

Compilation message

costinland.cpp: In function 'void special(ll)':
costinland.cpp:12:17: warning: statement has no effect [-Wunused-value]
   12 | #define DE(...) 0
      |                 ^
costinland.cpp:102:2: note: in expansion of macro 'DE'
  102 |  DE(K);
      |  ^~
costinland.cpp: In function 'void logone(ll)':
costinland.cpp:12:17: warning: statement has no effect [-Wunused-value]
   12 | #define DE(...) 0
      |                 ^
costinland.cpp:141:2: note: in expansion of macro 'DE'
  141 |  DE(check1());
      |  ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Correct! Your size: 5
2 Correct 1 ms 204 KB Correct! Your size: 5
3 Correct 1 ms 204 KB Correct! Your size: 5
4 Correct 1 ms 204 KB Correct! Your size: 5
5 Correct 1 ms 204 KB Correct! Your size: 5
6 Correct 1 ms 204 KB Correct! Your size: 5
7 Correct 1 ms 204 KB Correct! Your size: 5
8 Correct 1 ms 204 KB Correct! Your size: 5
9 Correct 1 ms 204 KB Correct! Your size: 5
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 332 KB Partially Correct! Your size: 60
2 Partially correct 1 ms 332 KB Partially Correct! Your size: 60
3 Partially correct 1 ms 204 KB Partially Correct! Your size: 61
4 Partially correct 1 ms 204 KB Partially Correct! Your size: 61
5 Partially correct 1 ms 336 KB Partially Correct! Your size: 61
6 Partially correct 1 ms 204 KB Partially Correct! Your size: 61
7 Partially correct 1 ms 332 KB Partially Correct! Your size: 61
8 Partially correct 1 ms 332 KB Partially Correct! Your size: 59