QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#236374#3033. Harry Potter and the Palindromic Radiusahsoltan#0 0ms0kbC++202.6kb2023-11-03 21:50:522023-11-03 21:50:53

Judging History

This is the latest submission verdict.

  • [2023-11-03 21:50:53]
  • Judged
  • Verdict: 0
  • Time: 0ms
  • Memory: 0kb
  • [2023-11-03 21:50:52]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define x first
#define y second
#define ir(x,a,b) ((a) <= (x) && (x) <= (b))
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define foru(i, n) for (int i = 0; i < n; ++i)
#define fori(i,a,n) for (int i = a; i < n; ++i)

// #ifdef LOCAL
// auto& operator<<(auto&, pair<auto, auto>);
// template<typename T, typename = T::value_type>
// auto& operator<<(auto& o, T x) requires (!same_as<T, string>) {
//   o << "{";
//   string s;
//   for (auto i : x) {
//     o << s << i;
//     s << ", ";
//   }
//   return o << "}";
// }
// auto& operator<<(auto& o, pair<auto, auto> p) {
//   return o << "(" << p.first << ", " << p.second << ")";
// }
// #define debug(x..) cerr << "["#x"]:",[](auto...$){((cerr<<" "<<$),...)<<endl;}(x)
// #else
// #define debug(...) 2137
// #endif

const int N = 1000100;
int n;
vector<pair<int, int>> adj[N];
bool vis[N];
int x[N];

void neq(int a, int b) {
  adj[a].push_back({b, 1});
  adj[b].push_back({a, 1});
}

void eq(int a, int b) {
  adj[a].push_back({b, 0});
  adj[b].push_back({a, 0});
}

bool dfs(int u) {
  vis[u] = true;
  for (auto [v, xx] : adj[u]) {
    if (!vis[v]) {
      x[v] = x[u] ^ xx;
      if (!dfs(v)) {
        return false;
      }
    } else if ((x[u] ^ xx) != x[v]) {
      return false;
    }
  }
  return true;
}

void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    adj[i].clear();
  }
  int l = 0, r = 0;
  foru (i, n) {
    int x;
    cin >> x;

    if (i-x > 0 && i+x < n-1) neq(i-x-1, i+x+1);
    if (x + i > r) {
      //cerr << x << " " << i << " " << r << endl;
      for (int j = max(i+1, r+1), k = i-(j-i); j <= min(n-1, i + x) && k >= 0; ++j, --k) {
        eq(j, k);
      }
      r = i + x, l = i - x;
    }
  }
  for (int i = 0; i < n; i++) {
    vis[i] = false;
    x[i] = 0;
  }
  vector<int> v;
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      if (!dfs(i)) {
        cout << 0 << '\n';
        return;
      }
      v.push_back(i);
    }
  }
  cout << (1 << ssize(v)) << '\n';
  for (int msk = 0; msk < 1 << ssize(v); msk++) {
    for (int i = 0; i < n; i++) {
      x[i] = 0;
      vis[i] = false;
    }
    for (int i = 0; i < ssize(v); i++) {
      x[v[i]] = (msk >> (ssize(v) - 1 - i)) & 1;
      assert(dfs(v[i]));
    }
    string s(n, '0');
    for (int i = 0; i < n; i++) {
      s[i] = x[i] + '0';
    }
    cout << s << '\n';
for (int i = 0; i < n; i++) {
       x[i] = 0;
       vis[i] = false;
     }
  }
  /*for (int i : v) {
    cerr << i << ' ';
  }
  cerr << '\n';*/
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Output Limit Exceeded

input:

131112
2
0 0
2
0 1
2
0 0
2
1 0
2
0 0
2
0 1
2
0 0
2
0 1
3
0 1 0
3
0 1 1
3
0 0 0
3
0 1 0
3
0 1 0
3
0 2 0
3
0 0 0
3
1 0 0
3
0 0 0
3
1 0 0
3
0 1 0
3
0 2 0
3
0 0 0
3
0 0 1
3
0 1 0
3
0 2 0
4
0 1 1 0
4
0 1 2 0
4
0 0 1 0
4
0 0 1 1
4
0 1 0 0
4
0 1 0 1
4
0 0 0 0
4
0 0 1 0
4
0 0 1 0
4
1 0 1 0
4
0 1 1 0
4
0 1 2...

output:

4
00
01
10
11
4
00
01
10
11
4
00
01
10
11
4
00
01
10
11
4
00
01
10
11
4
00
01
10
11
4
00
01
10
11
4
00
01
10
11
4
000
010
101
111
4
000
010
101
111
4
001
011
100
110
4
000
010
101
111
4
000
010
101
111
4
000
010
101
111
4
001
011
100
110
4
001
011
100
110
4
001
011
100
110
4
001
011
100
110
4
000
01...

result: