Submission #129194

# Submission time Handle Problem Language Result Execution time Memory
129194 2019-07-11T19:52:17 Z Mohammad_Yasser Lamps (JOI19_lamps) C++14
0 / 100
1000 ms 57356 KB
#ifndef Local
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;

const int N = 1e6 + 5;

string a;
string b;

int pos[N];
int n;

void compress() {
  string s = b;
  string res = s.substr(0, 1);

  for (int i = 0; i < n; ++i) {
    if (s[i] != res.back()) {
      res += s[i];
    }
    pos[i] = res.size() - 1;
  }
}

int memo[N];

int getCost(int i, int j) {
  return (pos[j] - pos[i] + 2) / 2;
}

int solve(int ind) {
  if (ind == n) return 0;
  int& res = memo[ind];
  if (res != -1) return res;
  if (a[ind] == b[ind]) return res = solve(ind + 1);
  res = 5e8;

  // Set
  for (int i = ind; i < n; ++i) {
    if (b[i] != b[ind]) continue;
    res = min(res, getCost(ind, i) + solve(i + 1));
  }

  // Toggle
  int r = ind;
  while (r < n && a[r] != b[r]) {
    ++r;
  }

  res = min(res, 1 + solve(r));

  return res;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cerr.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  cin >> n >> a >> b;

  compress();

  memset(memo, -1, sizeof memo);

  cout << solve(0) << endl;
}

Compilation message

lamp.cpp:5:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/STACK:1024000000,1024000000")
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4216 KB Output is correct
2 Correct 6 ms 4216 KB Output is correct
3 Correct 6 ms 4216 KB Output is correct
4 Correct 6 ms 4216 KB Output is correct
5 Correct 6 ms 4216 KB Output is correct
6 Correct 6 ms 4216 KB Output is correct
7 Correct 6 ms 4216 KB Output is correct
8 Correct 6 ms 4216 KB Output is correct
9 Correct 5 ms 4216 KB Output is correct
10 Correct 6 ms 4216 KB Output is correct
11 Correct 13 ms 4344 KB Output is correct
12 Correct 6 ms 4088 KB Output is correct
13 Incorrect 5 ms 4216 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4216 KB Output is correct
2 Correct 6 ms 4216 KB Output is correct
3 Correct 6 ms 4216 KB Output is correct
4 Correct 6 ms 4216 KB Output is correct
5 Correct 6 ms 4216 KB Output is correct
6 Correct 6 ms 4216 KB Output is correct
7 Correct 6 ms 4216 KB Output is correct
8 Correct 6 ms 4216 KB Output is correct
9 Correct 5 ms 4216 KB Output is correct
10 Correct 6 ms 4216 KB Output is correct
11 Correct 13 ms 4344 KB Output is correct
12 Correct 6 ms 4088 KB Output is correct
13 Incorrect 5 ms 4216 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4216 KB Output is correct
2 Correct 5 ms 4216 KB Output is correct
3 Correct 6 ms 4216 KB Output is correct
4 Correct 5 ms 4216 KB Output is correct
5 Correct 5 ms 4216 KB Output is correct
6 Correct 5 ms 4216 KB Output is correct
7 Correct 67 ms 57172 KB Output is correct
8 Execution timed out 1082 ms 57356 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4216 KB Output is correct
2 Correct 6 ms 4216 KB Output is correct
3 Correct 6 ms 4216 KB Output is correct
4 Correct 6 ms 4216 KB Output is correct
5 Correct 6 ms 4216 KB Output is correct
6 Correct 6 ms 4216 KB Output is correct
7 Correct 6 ms 4216 KB Output is correct
8 Correct 6 ms 4216 KB Output is correct
9 Correct 5 ms 4216 KB Output is correct
10 Correct 6 ms 4216 KB Output is correct
11 Correct 13 ms 4344 KB Output is correct
12 Correct 6 ms 4088 KB Output is correct
13 Incorrect 5 ms 4216 KB Output isn't correct
14 Halted 0 ms 0 KB -