QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#715579#8209. Curly Palindromesucup-team5071#WA 1ms3560kbC++202.2kb2024-11-06 12:39:362024-11-06 12:39:36

Judging History

This is the latest submission verdict.

  • [2024-11-06 12:39:36]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3560kb
  • [2024-11-06 12:39:36]
  • Submitted

answer

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

typedef unsigned long long ull;

const ull mask = std::chrono::steady_clock::now().time_since_epoch().count();

ull h(ull x){
    return x * x * x * 1237123 + 19260817;
}
ull f(ull x){
    ull cur = h(x & ((1ll<<31) - 1)) + h(x >> 31);
    return cur;
}
ull shift(ull x){
    x ^= mask;
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
    x ^= mask;
    return x;
}
ull treescnt;
ull _hash[10000];

ull getHash(int x, int p,const vector<vector<int>>& G){
    _hash[x] = 1;
    for (int i : G[x]){
        if (i == p) continue;
        getHash(i,x,G);
        _hash[x] += shift(_hash[i]);
    }
    return _hash[x];
}


void cal(const int& n,vector<int>& prefur){

    // prefur = vector<int>{3,4,3};

    set<int> exist;
    vector<int> cnt(n+1);
    for (int x : prefur){
        cnt[x]++;
    }
    for (int i = 1; i <= n; ++i){
        if (cnt[i] == 0){
            exist.insert(i);
        }
    }
    vector<vector<int>> G(n+1);
    for (int i = 0; i < n-2; ++i){
        int minele = *exist.begin();
        G[minele].push_back(prefur[i]);
        G[prefur[i]].push_back(minele);
        exist.erase(minele);
        if (--cnt[prefur[i]] == 0){
            exist.insert(prefur[i]);
        }
    }

    // assert(exist.size() == 2);
    auto it = exist.begin(); it++;
    G[*exist.begin()].push_back(*it);
    G[*it].push_back(*exist.begin());
    set<ull> hashed;
    for (int i = 1; i <= n; ++i){
        ull x = getHash(i,i,G);
        if (!hashed.count(x)){
            hashed.insert(x);
        } else {
            return ;
        }
    }
    cout << "TREE: " << endl;
    for (int i = 1; i <= n; ++i){
        for (auto x : G[i]){
            cout << i << " " << x << endl;
        }
    }
    treescnt++;
}

void dfs(int x,const int& n,vector<int>& vec){
    if (x == n-2){
        cal(n,vec);
    } else {
        for (int i = 1; i <= n; ++i){
            vec[x] = i;
            dfs(x+1,n,vec);
        }
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n = 6;
    vector<int> prefur(n-2);
    treescnt = 0;
    dfs(0,n,prefur);
    cout << treescnt << endl;

}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3560kb

input:

4
0 0 o
1 1 c
2 2 p
3 3 c

output:

0

result:

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