217572026-01-13 19:11:14ubormaciJárdakövezés háromféle elemmelcpp17Elfogadva 30/3013ms7332 KiB
#include <iostream>
#include <algorithm> // for sort, mainly
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <array>
#include <string>
#include <cstdio>
#include <iterator>
#include <unordered_set>
#include <cstdint> // for int64_t, int32_t, etc
#include <queue>
#include <stack>
#include <deque>
#include <numeric> // gcd, lcm
#include <fstream>
#include <bitset> // for bitset
#include <iomanip>
#include <cassert> // for set with custom ordering
#include <type_traits> // for set with custom ordering
#include <utility> // for swap, forward, etc
using namespace std;

#pragma GCC optimize("O2")
// #pragma GCC optimize("O1","O2","O3","Ofast","unroll-loops")
// #pragma GCC target("sse","sse2","sse3","sse4.1","sse4.2","avx","avx2","fma")

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

/*

notes:

int64_t
stoi(string s) -> string to int
to_string() -> int (or else) to string

vector declaration:
vector<ll> v(n, 0)
vector<vector<ll>> v(n, vector<ll>(n, 0));

{if statement} ? {truth value} : {false value}

#ifdef LOCAL
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif

cout << fixed << setprecision(n);

set with custom ordering
set<ll, decltype(&cmp)> qu(cmp);

*/

typedef int64_t ll;

const ll md = 2023;

void solve() {
	
	ll n;
	cin >> n;

	vector<vector<ll>> dp(n+1, vector<ll>(4,0));
	dp[0][3] = 1;
	for(ll i = 1; i <= n; i++) {

		// hozzaadunk egy vizszinteset
		// vagy egyet, vagy kettot felforditva

		//cerr << "\ni=" << i;

		dp[i][3] += dp[i-1][3];
		if(i > 1) {
			dp[i][3] += dp[i-2][3];
		}

		// egy-egy vizszintes
		dp[i][1] += dp[i-1][2];
		dp[i][2] += dp[i-1][1];

		//cerr << "\n2x1 berakva, dp=" << dp;

		// lepcso
		// * *
		// *

		// *
		// * *

		if(i > 1) {
			dp[i][1] += dp[i-2][3];
			dp[i][2] += dp[i-2][3];
		}

		// * *
		//   *

		//   * 
		// * *
		dp[i][3] += dp[i-1][2];
		dp[i][3] += dp[i-1][1];

		//cerr << "\nlepcso berakva, dp=" << dp;

		// hozzaadunk egy kicsit
		// vagy egyet fent
		// vagy egyet lent
		// vagy kettot

		//dp[i][3] += dp[i-1][3]; // kettot egymasra teve

		dp[i][1] += dp[i-1][3]; // egyet fel

		dp[i][3] += dp[i][1];
		dp[i][3] += dp[i][2];

		dp[i][2] += dp[i-1][3]; // egyet le

		dp[i][1] %= md;
		dp[i][2] %= md;
		dp[i][3] %= md;

		//cerr << "\n1x1 berakva, dp=" << dp;

	}

	/*
	for(ll i = 1; i <= n; i++) {
		cerr << "\ni=" << i << "; fill=" << dp[i][3];
	}*/

	//cerr << "\ndp=" << dp;

	cout << dp[n][3];

}

int main()
{
	std::ios_base::sync_with_stdio(false);
	//cin.tie(nullptr);
	//cout.tie(nullptr);

	solve();

	return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base30/30
1Elfogadva0/01ms316 KiB
2Elfogadva0/01ms316 KiB
3Elfogadva2/21ms500 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva2/21ms508 KiB
6Elfogadva2/21ms316 KiB
7Elfogadva2/21ms316 KiB
8Elfogadva2/21ms316 KiB
9Elfogadva2/24ms2356 KiB
10Elfogadva2/24ms2616 KiB
11Elfogadva2/28ms5056 KiB
12Elfogadva3/310ms5756 KiB
13Elfogadva3/32ms820 KiB
14Elfogadva3/32ms1076 KiB
15Elfogadva3/313ms7332 KiB