Submission #699015

# Submission time Handle Problem Language Result Execution time Memory
699015 2023-02-15T10:28:49 Z dattranxxx Fibonacci representations (CEOI18_fib) C++11
0 / 100
1 ms 340 KB
#include<bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int a[N];
int n;

multiset<int> s;
void fix(int x) {
  int c = s.count(x);
  if (c == 1) {
    if (s.count(x - 1)) {
      s.erase(x - 1);
      s.erase(x);
      s.insert(x + 1);
      fix(x + 1);
      return;
    }

    if (s.count(x + 1)) {
      s.erase(x + 1);
      s.erase(x);
      s.insert(x + 2);
      fix(x + 2);
    }

    return;

  }
  // c == 2
  if (x == 1) {
    s.erase(x);
    s.insert(x + 1);
    fix(x + 1);
    return;
  }

  if (s.count(x + 1)) {
    s.erase(s.find(x));
    s.erase(x + 1);
    s.insert(x + 2);
    fix(x + 2);
    return;
  }

  if (s.count(x - 1)) {
    s.erase(s.find(x));
    s.erase(x - 1);
    s.insert(x + 1);
    fix(x + 1);
    return;
  }

  if (x == 2) {
    s.erase(x);
    s.insert(x - 1);
    s.insert(x + 1);
  } else {
    s.erase(x);
    s.insert(x - 2);
    s.insert(x + 1);
    fix(x - 2);
  }

}

int b[N], dp[N][2];

int main() {
  cin.tie(0)->sync_with_stdio(0);


  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }

  for (int i = 1; i <= n; ++i) {
    s.insert(a[i]);
    fix(a[i]);

    int m = 0;
    for (int x : s) b[++m] = x;

//    for (int i = 1; i <= m; ++i) {
//      cerr << b[i] << " \n"[i == m];
//    }

    dp[1][0] = 1;
    dp[1][1] = (b[1] - 1) / 2;
    for (int i = 2; i <= m; ++i) {
      int len = b[i] - b[i - 1];
      if (len & 1) {
        dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]);
        dp[i][1] = (dp[i - 1][0] + dp[i - 1][1]) * (len / 2);
      } else {
        dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
        dp[i][1] = dp[i - 1][0] * (len / 2 - 1) + dp[i - 1][1] * (len / 2);
      }
    }
    cout << (dp[m][0] + dp[m][1]) << '\n';

  }

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -