Submission #1092553

# Submission time Handle Problem Language Result Execution time Memory
1092553 2024-09-24T11:30:23 Z juicy Nice sequence (IZhO18_sequence) C++17
0 / 100
3 ms 1884 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int N = 4e5 + 5;
 
int a, b;
int lt[N], rt[N], vis[N], pf[N];
bool cyc;
 
int timer;
 
void dfs(int u) {
  vis[u] = 1;
  for (auto v : {lt[u], rt[u]}) {
    if (~v) {
      if (!vis[v]) {
        dfs(v);
        if (cyc) {
          return;
        }
      } else if (vis[v] == 1) {
        cyc = 1;
        return;
      }
    }
  }
  vis[u] = 2;
  pf[u] = ++timer;
}
 
void add(int n) {
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i <= n; ++i) {
    lt[i] = i >= b ? i - b : -1;
    rt[i] = i + a <= n ? i + a : -1;
  }
  timer = 0;
}
 
bool check(int n) {
  cyc = 0;
  for (int i = 0; i <= n; ++i) {
    if (!vis[i]) {
      dfs(i);
      if (cyc) {
        return 0;
      }
    }
  }
  return 1;
}
 
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
 
  int t; cin >> t;
  while (t--) {
    cin >> a >> b;
    int l = 1, r = a + b - 1, res = 0;
    while (l <= r) {
      int m = (l + r) / 2;
      add(m);
      if (check(m)) {
        res = m;
        l = m + 1;
      } else {
        r = m - 1;
      }
    }
    cout << res << "\n";
    add(res);
    for (int i = 0; i <= res; ++i) {
      if (!vis[i]) {
        dfs(i);
      }
    }
    for (int i = 0; i <= res; ++i) {
      pf[i] -= pf[0];
    }
    for (int i = 1; i <= res; ++i) { 
      cout << pf[i] - pf[i - 1] << " ";
    }
    cout << "\n";
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1880 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1884 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1880 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1884 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1880 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1880 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1880 KB there is incorrect sequence
2 Halted 0 ms 0 KB -