Submission #554636

#TimeUsernameProblemLanguageResultExecution timeMemory
554636pavementLamps (JOI19_lamps)C++17
100 / 100
228 ms121764 KiB
#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][3][2]; bool A[1000005], B[1000005]; char C; int dp(int n, int a, bool b) { if (n == N + 1) return (a == 2 ? 0 : 1e9); if (mem[n][a][b] != -1) return mem[n][a][b]; int ret = 1e9; bool x = A[n]; if (a != 2) x = a; for (int k = 0; k < 3; k++) ret = min(ret, dp(n + 1, k, x != B[n]) + ((k != a) && k != 2)); mem[n][a][b] = ret + ((x != B[n]) && !b); return mem[n][a][b]; } main() { memset(mem, -1, sizeof mem); ios::sync_with_stdio(0); cin.tie(0); cin >> N; 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 << min({dp(1, 0, 0) + 1, dp(1, 1, 0) + 1, dp(1, 2, 0)}) << '\n'; }

Compilation message (stderr)

lamp.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   45 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...