← Real problems

aac5p4

easyconstructivemathStatement on DMOJ

CP Lang

12 lineschecks
// aac5p4: written from the accepted solution (corpus/submissions/4239900.cpp).
let (n, x) = read<(1..=1_000_000_000, Int)>()
fn most(n: Int, x: Int) -> Int:
    if n == 1:
        return 0
    if n % 2 == 0:
        return n / 2
    let r = (n - 3) / 2 % 4
    n / 2 + Int((x % 2 == 1) != (r == 0 or r == 3))
let k = most(n, x)
print(k)
print(1..=k, sep: "\n")

Accepted C++

71 lines · 0.76 s on the judge
#include "bits/extc++.h"

using namespace std;

template <typename T>
void dbgh(const T& t) {
	cerr << t << endl;
}

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
	cerr << t << " | ";
	dbgh(u...);
}

#ifdef DEBUG
#define dbg(...)                                           \
	cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
		 << ": ";                                          \
	dbgh(__VA_ARGS__)
#else
#define cerr   \
	if (false) \
	cerr
#define dbg(...) 1412
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())

int solve2(int n, int x) {
	int ans = n / 2;
	if (n & 1) {
		n -= 3;
		n /= 2;
		if (n % 4 == 0 || n % 4 == 3) {
			ans += !(x & 1);
		} else {
			ans += x & 1;
		}
	}
	return ans;
}

void solve() {
	int n, x;
	cin >> n >> x;
	if (n == 1) {
		cout << 0 << endl;
		return;
	}
	int ans = solve2(n, x);
	cout << ans << endl;
	for (int i = 0; i < ans; i++) {
		cout << i + 1 << endl;
	}
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cin.exceptions(ios::failbit);
	int t = 1;
	// cin >> t;
	for (int _ = 1; _ <= t; _++) {
		dbg(_);
		// cout << "Case #" << _ << ": ";
		solve();
	}
}