답안 #564518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
564518 2022-05-19T10:21:02 Z DanShaders Broken Device 2 (JOI22_device2) C++17
80 / 100
71 ms 3236 KB
//bs:flags:grader.cpp
#include "Anna.h"
#include "Bruno.h"

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

namespace x = __gnu_pbds;
template <typename T>
using ordered_set = x::tree<T, x::null_type, less<T>, x::rb_tree_tag, x::tree_order_statistics_node_update>;

template <typename T>
using normal_queue = priority_queue<T, vector<T>, greater<>>;

#define all(x) begin(x), end(x)
#define sz(x) ((int) (x).size())
#define x first
#define y second
using ll = long long;
using ld = long double;

int Declare() {
	return 181;
}

pair<vector<int>, vector<int>> Anna(ll n) {
	vector<int> u;
	for (; n; n /= 2) {
		u.push_back(n & 1);
	}

	vector<int> s = {1};
	for (int i : u) {
		if (i) {
			s.push_back(s.back() ^ 1);
		}
		s.push_back(s.back());
		s.push_back(s.back());
	}

	vector<int> t = {1};
	while (sz(t) != sz(s)) {
		t.push_back(t.back() ^ 1);
	}
	// for (int x : s) {
	// 	cout << x << " ";
	// }
	// cout << endl;
	// for (int x : t) {
	// 	cout << x << " ";
	// }
	// cout << endl;
	return {s, t};
}

vector<pair<int, int>> path;

#define TRY(x) do { if (x) { return true; }} while (false);

bool recover(const vector<int> &a, int i, int tlen, int cnt) {
	if (i == sz(a)) {
		return 2 * tlen == sz(a) && !cnt;
	}
	
	if (2 * tlen > sz(a)) {
		return false;
	}

	if (a[i] != (tlen & 1)) {
		TRY(recover(a, i + 1, tlen + 1, cnt));
	}
	if (cnt) {
		if (path.back().x != a[i]) {
			return false;
		}
		TRY(recover(a, i + 1, tlen, cnt - 1));
	} else {
		int prv = 1;
		if (sz(path)) {
			prv = path.back().x;
		}
		path.push_back({a[i], a[i] != prv});
		TRY(recover(a, i + 1, tlen, a[i] == prv ? 1 : 2));
		path.pop_back();
	}
	return false;
}

ll Bruno(vector<int> a) {
	path.clear();
	// for (int x : a) {
	// 	cout << x << " ";
	// }
	// cout << endl;
	if (!recover(a, 1, 0, 0)) {
		path.push_back({1, -1});
		assert(recover(a, 0, 0, 1));
		path.erase(path.begin());
	}
	// for (auto [_, x] : path) {
	// 	cout << x << " ";
	// }
	// cout << endl;
	ll n = 0;
	for (int i = 0; i < sz(path); ++i) {
		n |= path[i].y * (1ll << i);
	}
	return n;
}
//bs:flags:grader.cpp
#include "Anna.h"
#include "Bruno.h"

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

namespace x = __gnu_pbds;
template <typename T>
using ordered_set = x::tree<T, x::null_type, less<T>, x::rb_tree_tag, x::tree_order_statistics_node_update>;

template <typename T>
using normal_queue = priority_queue<T, vector<T>, greater<>>;

#define all(x) begin(x), end(x)
#define sz(x) ((int) (x).size())
#define x first
#define y second
using ll = long long;
using ld = long double;

int Declare() {
	return 181;
}

pair<vector<int>, vector<int>> Anna(ll n) {
	vector<int> u;
	for (; n; n /= 2) {
		u.push_back(n & 1);
	}

	vector<int> s = {1};
	for (int i : u) {
		if (i) {
			s.push_back(s.back() ^ 1);
		}
		s.push_back(s.back());
		s.push_back(s.back());
	}

	vector<int> t = {1};
	while (sz(t) != sz(s)) {
		t.push_back(t.back() ^ 1);
	}
	// for (int x : s) {
	// 	cout << x << " ";
	// }
	// cout << endl;
	// for (int x : t) {
	// 	cout << x << " ";
	// }
	// cout << endl;
	return {s, t};
}

vector<pair<int, int>> path;

#define TRY(x) do { if (x) { return true; }} while (false);

bool recover(const vector<int> &a, int i, int tlen, int cnt) {
	if (i == sz(a)) {
		return 2 * tlen == sz(a) && !cnt;
	}
	
	if (2 * tlen > sz(a)) {
		return false;
	}

	if (a[i] != (tlen & 1)) {
		TRY(recover(a, i + 1, tlen + 1, cnt));
	}
	if (cnt) {
		if (path.back().x != a[i]) {
			return false;
		}
		TRY(recover(a, i + 1, tlen, cnt - 1));
	} else {
		int prv = 1;
		if (sz(path)) {
			prv = path.back().x;
		}
		path.push_back({a[i], a[i] != prv});
		TRY(recover(a, i + 1, tlen, a[i] == prv ? 1 : 2));
		path.pop_back();
	}
	return false;
}

ll Bruno(vector<int> a) {
	path.clear();
	// for (int x : a) {
	// 	cout << x << " ";
	// }
	// cout << endl;
	if (!recover(a, 1, 0, 0)) {
		path.push_back({1, -1});
		assert(recover(a, 0, 0, 1));
		path.erase(path.begin());
	}
	// for (auto [_, x] : path) {
	// 	cout << x << " ";
	// }
	// cout << endl;
	ll n = 0;
	for (int i = 0; i < sz(path); ++i) {
		n |= path[i].y * (1ll << i);
	}
	return n;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 516 KB Output is correct
2 Correct 18 ms 976 KB Output is correct
3 Correct 18 ms 1080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 516 KB Output is correct
2 Correct 18 ms 976 KB Output is correct
3 Correct 18 ms 1080 KB Output is correct
4 Correct 31 ms 1492 KB Output is correct
5 Correct 31 ms 1480 KB Output is correct
6 Correct 30 ms 1608 KB Output is correct
7 Correct 30 ms 1492 KB Output is correct
8 Correct 32 ms 1496 KB Output is correct
9 Correct 30 ms 1488 KB Output is correct
10 Correct 28 ms 1488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 516 KB Output is correct
2 Correct 18 ms 976 KB Output is correct
3 Correct 18 ms 1080 KB Output is correct
4 Correct 31 ms 1492 KB Output is correct
5 Correct 31 ms 1480 KB Output is correct
6 Correct 30 ms 1608 KB Output is correct
7 Correct 30 ms 1492 KB Output is correct
8 Correct 32 ms 1496 KB Output is correct
9 Correct 30 ms 1488 KB Output is correct
10 Correct 28 ms 1488 KB Output is correct
11 Correct 33 ms 1472 KB Output is correct
12 Correct 32 ms 1564 KB Output is correct
13 Correct 34 ms 1476 KB Output is correct
14 Correct 31 ms 1436 KB Output is correct
15 Correct 32 ms 1628 KB Output is correct
16 Correct 31 ms 1528 KB Output is correct
17 Correct 34 ms 1544 KB Output is correct
18 Correct 27 ms 1552 KB Output is correct
19 Correct 27 ms 1472 KB Output is correct
20 Correct 28 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 516 KB Output is correct
2 Correct 18 ms 976 KB Output is correct
3 Correct 18 ms 1080 KB Output is correct
4 Correct 31 ms 1492 KB Output is correct
5 Correct 31 ms 1480 KB Output is correct
6 Correct 30 ms 1608 KB Output is correct
7 Correct 30 ms 1492 KB Output is correct
8 Correct 32 ms 1496 KB Output is correct
9 Correct 30 ms 1488 KB Output is correct
10 Correct 28 ms 1488 KB Output is correct
11 Correct 33 ms 1472 KB Output is correct
12 Correct 32 ms 1564 KB Output is correct
13 Correct 34 ms 1476 KB Output is correct
14 Correct 31 ms 1436 KB Output is correct
15 Correct 32 ms 1628 KB Output is correct
16 Correct 31 ms 1528 KB Output is correct
17 Correct 34 ms 1544 KB Output is correct
18 Correct 27 ms 1552 KB Output is correct
19 Correct 27 ms 1472 KB Output is correct
20 Correct 28 ms 1492 KB Output is correct
21 Correct 36 ms 1528 KB Output is correct
22 Correct 38 ms 1748 KB Output is correct
23 Correct 35 ms 1800 KB Output is correct
24 Correct 36 ms 1648 KB Output is correct
25 Correct 35 ms 1688 KB Output is correct
26 Correct 37 ms 1716 KB Output is correct
27 Correct 34 ms 1800 KB Output is correct
28 Correct 31 ms 1588 KB Output is correct
29 Correct 32 ms 1628 KB Output is correct
30 Correct 36 ms 1600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 516 KB Output is correct
2 Correct 18 ms 976 KB Output is correct
3 Correct 18 ms 1080 KB Output is correct
4 Correct 31 ms 1492 KB Output is correct
5 Correct 31 ms 1480 KB Output is correct
6 Correct 30 ms 1608 KB Output is correct
7 Correct 30 ms 1492 KB Output is correct
8 Correct 32 ms 1496 KB Output is correct
9 Correct 30 ms 1488 KB Output is correct
10 Correct 28 ms 1488 KB Output is correct
11 Correct 33 ms 1472 KB Output is correct
12 Correct 32 ms 1564 KB Output is correct
13 Correct 34 ms 1476 KB Output is correct
14 Correct 31 ms 1436 KB Output is correct
15 Correct 32 ms 1628 KB Output is correct
16 Correct 31 ms 1528 KB Output is correct
17 Correct 34 ms 1544 KB Output is correct
18 Correct 27 ms 1552 KB Output is correct
19 Correct 27 ms 1472 KB Output is correct
20 Correct 28 ms 1492 KB Output is correct
21 Correct 36 ms 1528 KB Output is correct
22 Correct 38 ms 1748 KB Output is correct
23 Correct 35 ms 1800 KB Output is correct
24 Correct 36 ms 1648 KB Output is correct
25 Correct 35 ms 1688 KB Output is correct
26 Correct 37 ms 1716 KB Output is correct
27 Correct 34 ms 1800 KB Output is correct
28 Correct 31 ms 1588 KB Output is correct
29 Correct 32 ms 1628 KB Output is correct
30 Correct 36 ms 1600 KB Output is correct
31 Correct 44 ms 2140 KB Output is correct
32 Correct 44 ms 2152 KB Output is correct
33 Correct 45 ms 2176 KB Output is correct
34 Correct 45 ms 2176 KB Output is correct
35 Correct 45 ms 2188 KB Output is correct
36 Correct 48 ms 2196 KB Output is correct
37 Correct 44 ms 2144 KB Output is correct
38 Correct 40 ms 2072 KB Output is correct
39 Correct 43 ms 1964 KB Output is correct
40 Correct 41 ms 1980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 69 ms 3040 KB Output is partially correct
2 Partially correct 70 ms 3036 KB Output is partially correct
3 Partially correct 68 ms 3072 KB Output is partially correct
4 Partially correct 69 ms 3032 KB Output is partially correct
5 Partially correct 68 ms 3140 KB Output is partially correct
6 Partially correct 69 ms 3064 KB Output is partially correct
7 Partially correct 68 ms 3012 KB Output is partially correct
8 Partially correct 67 ms 3108 KB Output is partially correct
9 Partially correct 68 ms 3056 KB Output is partially correct
10 Partially correct 70 ms 3008 KB Output is partially correct
11 Partially correct 70 ms 3000 KB Output is partially correct
12 Partially correct 71 ms 3156 KB Output is partially correct
13 Partially correct 71 ms 3184 KB Output is partially correct
14 Partially correct 68 ms 3236 KB Output is partially correct
15 Partially correct 64 ms 2932 KB Output is partially correct
16 Partially correct 63 ms 2948 KB Output is partially correct
17 Partially correct 62 ms 2964 KB Output is partially correct
18 Partially correct 66 ms 2908 KB Output is partially correct
19 Partially correct 65 ms 2956 KB Output is partially correct
20 Partially correct 64 ms 3112 KB Output is partially correct