Submission #343777

# Submission time Handle Problem Language Result Execution time Memory
343777 2021-01-04T13:19:44 Z Pety Nice sequence (IZhO18_sequence) C++14
0 / 100
79 ms 14316 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O1")
#pragma GCC optimize ("O3")

using namespace std;

int top[1000002], k, ans[1000002], val[1000002], n, m, i;
bool viz[1000002];

void dfs (int x, int len) {
  viz[x] = 1;
  if (x + n <= len && !viz[x + n])
    dfs(x + n, len);
  if (x - m >= 0 && !viz[x - m])
    dfs(x - m, len);
  top[++k] = x;
}

bool ok (int len) {
  for (i = 0;i <= len; i++)
    val[i] = viz[i] = 0;
  k = 0;
  for (i = 0; i <= len; i++)
    if (!viz[i])
      dfs(i, len);
  for (i = 1; i <= len + 1; i++)
    val[top[i]] = i;
  for (i = 0; i <= len; i++) {
    if (i >= n && val[i] > val[i - n])
      return false;
    if (i + m <= len && val[i] > val[i + m])
      return false;
  }
  for (i = 1; i <= len; i++)
    ans[i] = val[i] - val[i - 1];
  return true;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int t;
  cin >> t;
  for (i = 1; i <= t; i++) {
    cin >> n >> m;
    int st = 1, dr = 500000, sol = 0;
    while (st <= dr) {
      int mij = ((st + dr) >> 1);
      if (ok(mij)) {
        sol = mij;
        st = mij + 1;
      }
      else
        dr = mij - 1;
    }
    cout << sol << "\n";
    ok(sol);
    for (i = 1; i <= sol; i++)
      cout << ans[i] << " ";
    cout << "\n";
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 79 ms 14316 KB Ok
2 Incorrect 7 ms 2796 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 8556 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 6508 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 8428 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 79 ms 14316 KB Ok
2 Incorrect 7 ms 2796 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 79 ms 14316 KB Ok
2 Incorrect 7 ms 2796 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 79 ms 14316 KB Ok
2 Incorrect 7 ms 2796 KB Unexpected end of file - int32 expected
3 Halted 0 ms 0 KB -