QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#833301 | #9241. Sphinx | le0n | 3 | 3ms | 4128kb | C++20 | 3.0kb | 2024-12-26 16:59:06 | 2024-12-26 16:59:08 |
answer
#include "sphinx.h"
#include <bits/stdc++.h>
using namespace std;
//perform_experiment
const int N = 255;
int col[N];
bool vis[N];
vector<int> e[N], T[2], tmp, res, owo;
int fa[N], tp[N], cnt[N], awa[N], cry[N];
int getf(int x)
{
return (fa[x] == x) ? x : (fa[x] = getf(fa[x]));
}
void un(int x, int y)
{
fa[getf(x)] = getf(y);
}
int num(int n, vector<int> p)
{
int i, c = 0;
for(i = 0; i < n; i++)
fa[i] = -1;
for(auto o: p)
fa[o] = o;
for(auto u: p)
for(auto v: e[u])
if(fa[v] != -1)
un(u, v);
for(auto o: p)
if(fa[o] == o)
++c;
return c;
}
int qwq(vector<int> G)
{
int n, i;
vector<int> tmp;
n = G.size();
for(i = 0; i < n; i++)
if(G[i] == n)
tmp.emplace_back(i);
return num(n, tmp);
}
void dfs(int x, int c)
{
col[x] = c;
vis[x] = 1;
for(auto y: e[x])
if(!vis[y])
dfs(y, 1 ^ c);
}
vector<int> find_colours(int n, vector<int> X, vector<int> Y)
{
vector<int> E(n, -1);
vector<int> G(n, 0);
int i, j, k, m = X.size(), x, y, l, r, mid, C = 0;
for(i = 0; i < m; i++)
{
e[X[i]].emplace_back(Y[i]);
e[Y[i]].emplace_back(X[i]);
}
dfs(1, 0);
for(i = 0; i < n; i++)
T[col[i]].emplace_back(i);
for(i = 0; i < 2; i++)
{
x = num(n, T[i ^ 1]);
res = T[i];
for(j = 0; j < n; j++)
tp[j] = 0;
for(auto o: T[i])
tp[o] = 1;
for(j = 0; j < n; j++)
G[j] = n;
y = 0;
for(j = 0; j < n; j++)
{
if(tp[j])
{
G[j] = -1;
cnt[j] = perform_experiment(G) - qwq(G);
++C;
}
else
cnt[j] = (j ? cnt[j - 1] : 0);
}
tmp.clear();
// for(auto o: T[i])
// cerr << "!" << i << " " << o << " " << cnt[o] << " " << x << endl;
for(j = 0; j < n; j++)
awa[j] = 0;
for(j = 0; j < n; j++)
{
if(res.empty())
break;
for(k = 0; k < n; k++)
G[k] = n;
for(auto o: res)
G[o] = -1;
for(auto o: T[i ^ 1])
G[o] = j;
y = perform_experiment(G) - qwq(G) - x - cnt[res.back()];
++C;
// cerr << "WOW" << j << " " << y << " " << res.size() << " " << qwq(G) << " " << x << " " << res.back() << " " << cnt[res.back()] << endl;
if(y == 0)
{
tmp.clear();
for(k = 0; k < n; k++)
awa[k] = 0;
continue;
}
l = 0;
r = res.size() - 1;
while(l <= r)
{
mid = (l + r) >> 1;
for(k = 0; k < n; k++)
G[k] = n;
for(k = 0; k <= mid; k++)
G[k] = -1;
for(auto o: T[i ^ 1])
G[o] = j;
y = perform_experiment(G) - qwq(G) - x - cnt[res[mid]];
++C;
if(y == 0)
l = mid + 1;
else
r = mid - 1;
}
E[res[l]] = j;
tmp.emplace_back(res[l]);
owo.clear();
for(auto o: res)
if(o != res[l])
owo.emplace_back(o);
res = owo;
owo.clear();
for(k = 0; k < n; k++)
cry[k] = 0;
for(auto o: tmp)
cry[o] = 1;
y = 0;
for(k = 0; k < n; k++)
{
if(cry[k])
{
owo.emplace_back(k);
y = num(n, owo);
}
if(y != awa[k])
{
cnt[k] += awa[k] - y;
awa[k] = y;
}
}
j--;
}
}
assert(C <= 2200);
return E;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 1ms
memory: 4112kb
input:
1978433568 2 1 0 1 1978433568 2 1978433568 1 1978433568 2 1978433568 2 1978433568 1 1978433568 1
output:
877694080 2 -1 877694080 0 -1 877694080 0 2 877694080 -1 2 877694080 -1 0 877694080 -1 0 877694081 0 0
result:
ok #experiments: 6
Test #2:
score: 3
Accepted
time: 1ms
memory: 3856kb
input:
1978433568 2 1 0 1 1978433568 2 1978433568 2 1978433568 1 1978433568 2 1978433568 2 1978433568 1 1978433568 1
output:
877694080 2 -1 877694080 0 -1 877694080 1 -1 877694080 1 2 877694080 -1 2 877694080 -1 0 877694080 -1 0 877694081 0 1
result:
ok #experiments: 7
Test #3:
score: 3
Accepted
time: 1ms
memory: 3824kb
input:
1978433568 2 1 0 1 1978433568 2 1978433568 1 1978433568 2 1978433568 2 1978433568 2 1978433568 1 1978433568 1
output:
877694080 2 -1 877694080 0 -1 877694080 0 2 877694080 -1 2 877694080 -1 0 877694080 -1 1 877694080 -1 1 877694081 1 0
result:
ok #experiments: 7
Test #4:
score: 3
Accepted
time: 1ms
memory: 3880kb
input:
1978433568 2 1 0 1 1978433568 2 1978433568 2 1978433568 1 1978433568 2 1978433568 2 1978433568 2 1978433568 1 1978433568 1
output:
877694080 2 -1 877694080 0 -1 877694080 1 -1 877694080 1 2 877694080 -1 2 877694080 -1 0 877694080 -1 1 877694080 -1 1 877694081 1 1
result:
ok #experiments: 8
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #5:
score: 7
Accepted
time: 3ms
memory: 4128kb
input:
1978433568 50 49 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 19784335...
output:
877694080 50 -1 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 877694080 50 -1 50 -1 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 5...
result:
ok #experiments: 304
Test #6:
score: 0
Wrong Answer
time: 0ms
memory: 3832kb
input:
1978433568 49 48 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 1978433568 3 1...
output:
877694080 49 -1 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 877694080 49 -1 49 -1 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 4...
result:
wrong answer Vertices 0 and 1 do have the same color, but they do not in returned answer
Subtask #3:
score: 0
Runtime Error
Test #34:
score: 0
Runtime Error
input:
1978433568 250 249 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 ...
output:
877694080 250 -1 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250...
result:
Subtask #4:
score: 0
Runtime Error
Test #43:
score: 0
Runtime Error
input:
1978433568 250 31125 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 0 14 0 15 0 16 0 17 0 18 0 19 0 20 0 21 0 22 0 23 0 24 0 25 0 26 0 27 0 28 0 29 0 30 0 31 0 32 0 33 0 34 0 35 0 36 0 37 0 38 0 39 0 40 0 41 0 42 0 43 0 44 0 45 0 46 0 47 0 48 0 49 0 50 0 51 0 52 0 53 0 54 0 55 0 56 0 57 0 5...
output:
877694080 250 -1 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250...
result:
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%