QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#235627#3033. Harry Potter and the Palindromic RadiuspiratZnachor#0 9420ms390016kbC++144.1kb2023-11-02 22:54:282023-11-02 22:54:29

Judging History

This is the latest submission verdict.

  • [2023-11-02 22:54:29]
  • Judged
  • Verdict: 0
  • Time: 9420ms
  • Memory: 390016kb
  • [2023-11-02 22:54:28]
  • Submitted

answer

#include <bits/stdc++.h>
#include <cassert>

using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vvi vector<vi>
#define vll vector<long long>
#define fi first
#define se second

const int N = 1e6 + 5;
const int K = 15;
vi G[N];
int odw[N];
bool vis[N];
int grupa[N];
int para[N];
int cnt;

vi ind[N];

vi vec;

void dfs(int v) {
    vis[v] = true;
    vec.pb(v);
    for (auto u : G[v]) {
        if (!vis[u]) dfs(u);
    }
}

bool cycle(int v) {
    odw[v] = 1;
    for (auto u : G[v]) {
        if (odw[u] == 0) {
            grupa[u] = grupa[v]^1;
            if (cycle(u)) {
                return true;
            }
        } else if (odw[u] == 1) {
            return true;
        }
    }
    odw[v] = 2;
    return false;
}

void test_case() {
    int n;
    cin >> n;

    cnt = 0;
    for (int i = 0; i < n; i ++) {
        G[i].clear();
        odw[i] = 0;
        ind[i].clear();
        grupa[i] = 0;
        para[i] = -1;
        vis[i] = false;
    }

    vi a(n);
    bool bad = false;
    for (int i = 0; i < n; i ++) {
        cin >> a[i];
        if (i - a[i] < 0 || i + a[i] >= n) {
            bad = true;
        }

        if (i - a[i] - 1 >= 0 && i + a[i] + 1 < n) {
            int v = i-a[i]-1, u = i+a[i]+1;
            //cout << "kr : " << v << ' ' << u << '\n';
            G[v].pb(u);
            G[u].pb(v);
        }
    }    

    //cout << "1\n";

    if (bad) {
        cout << 0 << '\n';
        return;
    }

    vi reszta;
    for (int i = 0; i < n; i ++) {
        if (!vis[i]) {
            //cout << "start : " << i << '\n';
            vec.clear();
            bad &= (!cycle(i)); 
            dfs(i);

            // for (auto it : vec) {
            //     cout << it << ' ';
            // }  
            // cout << '\n';

            if (vec.size() > 1) {
                for (auto it : vec) {
                    ind[cnt + grupa[it]].pb(it);
                }
                para[cnt] = cnt + 1;
                para[cnt + 1] = cnt;
                //cout << "para : " << cnt << ' ' << cnt + 1 << '\n';
                cnt += 2;
            } else {
                reszta.pb(i);
            }
        }
    }

    //cout << "tu\n";

    for (auto it : reszta) {
        ind[cnt].pb(it);
    }

    cnt ++;

    // for (int i = 0; i < cnt; i ++) {
    //     cout << "cnt : " << i << '\n';
    //     for (auto it : ind[i]) {
    //         cout << it << ' ';
    //     }
    //     cout << '\n';
    // }

    if (bad) {
        cout << 0 << '\n';
        return;
    }

    //cout << cnt << '\n';

    if (cnt >= K) {
        cout << 0 << '\n';
        return;
    }

    //assert(cnt < K);

    set<string> ans;

    for (int i = 0; i < (1 << cnt); i ++) {
        bool git = true;

        //cout << i << '\n';

        vector<vi> co(2);
        co[0].clear();
        co[1].clear();
        for (int j = 0; j < cnt; j ++) {
            //cout << "j : " << j << '\n';
            if (para[j] != -1) {
                int bit1 = i&(1<<j);
                int bit2 = i&(1<<para[j]);
                git &= (bool(bit1) != bool(bit2));
            }
            bool xd = bool(i&(1<<j));
            co[xd].pb(j);
        }

        //cout << "po " << i << '\n';

        if (git) {
            string s(n, '?');
            for (int k = 0; k < 2; k ++) {
                for (auto it : co[k]) {
                    for (auto it2 : ind[it]) {
                        s[it2] = char('0'+k);
                    }
                }
            }

            ans.insert(s);
        }
    }

    //cout << "tam\n";

    cout << ans.size() << '\n';
    for (auto it : ans) cout << it << '\n';
}

int32_t main() {
    // ios::sync_with_stdio(0);
    // cin.tie(0);
    // cout.tie(0);

    int tc = 1;
    cin >> tc;
    while(tc--) {
        test_case();
    }
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 9420ms
memory: 390016kb

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:

2
00
11
0
2
00
11
0
2
00
11
0
2
00
11
0
2
000
111
0
4
001
011
100
110
2
000
111
2
000
111
0
4
001
011
100
110
0
4
001
011
100
110
0
2
000
111
0
4
001
011
100
110
0
2
000
111
0
2
0000
1111
0
4
0010
0111
1000
1101
0
4
0001
0100
1011
1110
0
4
0011
0110
1001
1100
4
0010
0111
1000
1101
4
0010
0111
1000
1...

result:

wrong answer 1st lines differ - expected: '4', found: '2'