답안 #553893

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
553893 2022-04-27T09:02:11 Z pavement Lamps (JOI19_lamps) C++17
0 / 100
104 ms 262144 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
//#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using db = double;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
using iiii = tuple<int, int, int, int>;
template<class key, class value = null_type, class cmp = less<key> >
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

int N, mem[1000005][365];
bool A[1000005], B[1000005];
char C;

vector<ii> vec;

bool apply(bool x, int b) {
	int bm = vec[b].second;
	for (int k = 0; k < vec[b].first; k++) {
		if (bm % 3 == 0) x = 0;
		else if (bm % 3 == 1) x = 1;
		else x ^= 1;
		bm /= 3;
	}
	return x;
}

int cst(int a, int b) {
	int lcp = 0, bma = vec[a].second, bmb = vec[b].second;
	for (int i = 0; i < min(vec[a].first, vec[b].first); i++) {
		if (bma % 3 == bmb % 3) lcp = i + 1;
		else break;
		bma /= 3;
		bmb /= 3;
	}
	return vec[b].first - lcp;
}

int dp(int n, int b) {
	if (n == N + 1) return 0;
	if (mem[n][b] != -1) return mem[n][b];
	int ret = INT_MAX;
	for (int nb = 0; nb < vec.size(); nb++)
		if (apply(A[n], nb) == B[n]) ret = min(ret, dp(n + 1, nb) + cst(b, nb));
	return mem[n][b] = ret;
}

main() {
	memset(mem, -1, sizeof mem);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for (int i = 0, p = 1; i <= 5; i++) {
		for (int j = 0; j < p; j++) vec.eb(i, j);
		p *= 3;
	}
	for (int i = 1; i <= N; i++) {
		cin >> C;
		A[i] = C == '1';
	}
	for (int i = 1; i <= N; i++) {
		cin >> C;
		B[i] = C == '1';
	}
	cout << dp(1, 0) << '\n';
}

Compilation message

lamp.cpp: In function 'int dp(int, int)':
lamp.cpp:61:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for (int nb = 0; nb < vec.size(); nb++)
      |                   ~~~^~~~~~~~~~~~
lamp.cpp: At global scope:
lamp.cpp:66:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   66 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 101 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 101 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 104 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 101 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -