QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#711145 | #9241. Sphinx | ivan_alexeev# | 3 | 10ms | 4076kb | C++23 | 3.5kb | 2024-11-05 00:58:47 | 2024-11-05 00:58:48 |
Judging History
answer
#include <bits/stdc++.h>
#include "sphinx.h"
using namespace std;
#ifdef lisie_bimbi
#else
#define endl '\n'
#endif
typedef long long ll;
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,bmi2,fma")
const ll inf = 1'000'000'000;
#ifdef lisie_bimbi
namespace {
const int CALLS_CNT_LIMIT = 2750;
int calls_cnt;
int N, M;
std::vector<int> C;
std::vector<int> X, Y;
std::vector<std::vector<int>> adj;
void quit(const char* message) {
printf("%s\n", message);
exit(0);
}
int count_components(const std::vector<int>& S) {
int components_cnt = 0;
std::vector<bool> vis(N, false);
for (int i = 0; i < N; i++) {
if (vis[i])
continue;
components_cnt++;
std::queue<int> q;
vis[i] = true;
q.push(i);
while (!q.empty()) {
int cur = q.front();
q.pop();
for (int nxt : adj[cur])
if (!vis[nxt] && S[nxt] == S[cur]) {
vis[nxt] = true;
q.push(nxt);
}
}
}
return components_cnt;
}
} // namespace
int perform_experiment(std::vector<int> E) {
calls_cnt++;
if (calls_cnt > CALLS_CNT_LIMIT)
quit("Too many calls");
if ((int)E.size() != N)
quit("Invalid argument");
for (int i = 0; i < N; i++)
if (!(-1 <= E[i] && E[i] <= N))
quit("Invalid argument");
std::vector<int> S(N);
for (int i = 0; i < N; i++)
S[i] = (E[i] == -1 ? C[i] : E[i]);
return count_components(S);
}
#endif
vector<vector<int>> v;
vector<int> used;
void dfs(int u){
used[u] = 1;
for(auto i : v[u]){
if(!used[i]){
dfs(i);
}
}
}
vector<int> find_colours(int n, vector<int> x, vector<int> y){
v.resize(n);
for(int i = 0; i < n; i++){
v[x[i]].push_back(y[i]);
v[y[i]].push_back(x[i]);
}
vector<int> c(n);
for(int u = 0; u < n; u++){
vector<int> e(n, n);
e[u] = -1;
used.clear();
used.resize(n);
used[v[u][0]] = 1;
used[u] = 1;
int cnt = 0;
for(int i = 0; i < n; i++){
if(!used[i]){
cnt++;
dfs(i);
}
}
for(int i = 0; i < n; i++){
e[v[u][0]] = i;
int x = perform_experiment(e);
if(x == cnt + 1){
c[u] = i;
break;
}
}
}
return c;
}
#ifdef lisie_bimbi
int main() {
#ifdef lisie_bimbi
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
cin.tie(nullptr)->sync_with_stdio(false);
#endif
assert(2 == scanf("%d%d", &N, &M));
C.resize(N);
for (int i = 0; i < N; i++)
assert(1 == scanf("%d", &C[i]));
X.resize(M), Y.resize(M);
for (int j = 0; j < M; j++)
assert(2 == scanf("%d%d", &X[j], &Y[j]));
fclose(stdin);
adj.assign(N, std::vector<int>());
for (int j = 0; j < M; j++) {
adj[X[j]].push_back(Y[j]);
adj[Y[j]].push_back(X[j]);
}
calls_cnt = 0;
std::vector<int> G = find_colours(N, X, Y);
int L = G.size();
printf("%d %d\n", L, calls_cnt);
for (int i = 0; i < L; i++)
printf("%s%d", (i == 0 ? "" : " "), G[i]);
printf("\n");
fclose(stdout);
return 0;
}
#endif
/*
signed main(){
#ifdef lisie_bimbi
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
cin.tie(nullptr)->sync_with_stdio(false);
#endif
int t = 1;
cin >> t;
while(t--){
solve();
}
return 0;
}
*/
详细
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 1ms
memory: 3792kb
input:
1978433568 2 1 0 1 1978433568 1 1978433568 1
output:
877694080 -1 0 877694080 0 -1 877694081 0 0
result:
ok #experiments: 2
Test #2:
score: 3
Accepted
time: 0ms
memory: 3780kb
input:
1978433568 2 1 0 1 1978433568 1 1978433568 2 1978433568 1
output:
877694080 -1 0 877694080 0 -1 877694080 1 -1 877694081 0 1
result:
ok #experiments: 3
Test #3:
score: 3
Accepted
time: 0ms
memory: 3856kb
input:
1978433568 2 1 0 1 1978433568 2 1978433568 1 1978433568 1
output:
877694080 -1 0 877694080 -1 1 877694080 0 -1 877694081 1 0
result:
ok #experiments: 3
Test #4:
score: 3
Accepted
time: 1ms
memory: 3780kb
input:
1978433568 2 1 0 1 1978433568 2 1978433568 1 1978433568 2 1978433568 1
output:
877694080 -1 0 877694080 -1 1 877694080 0 -1 877694080 1 -1 877694081 1 1
result:
ok #experiments: 4
Subtask #2:
score: 0
Runtime Error
Dependency #1:
100%
Accepted
Test #5:
score: 7
Accepted
time: 7ms
memory: 4036kb
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 -1 0 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 -1 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 ...
result:
ok #experiments: 1250
Test #6:
score: 7
Accepted
time: 7ms
memory: 3784kb
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 -1 0 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 -1 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 ...
result:
ok #experiments: 785
Test #7:
score: 7
Accepted
time: 4ms
memory: 3804kb
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 -1 0 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 -1 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 ...
result:
ok #experiments: 1613
Test #8:
score: 7
Accepted
time: 0ms
memory: 3784kb
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 -1 0 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 -1 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 ...
result:
ok #experiments: 1353
Test #9:
score: 7
Accepted
time: 10ms
memory: 4076kb
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 -1 0 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 -1 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 ...
result:
ok #experiments: 1138
Test #10:
score: 7
Accepted
time: 4ms
memory: 3824kb
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 2 1...
output:
877694080 -1 0 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 0 -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 ...
result:
ok #experiments: 978
Test #11:
score: 7
Accepted
time: 0ms
memory: 3732kb
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 -1 0 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 -1 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 ...
result:
ok #experiments: 1278
Test #12:
score: 7
Accepted
time: 0ms
memory: 3780kb
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 -1 0 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 -1 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 ...
result:
ok #experiments: 1275
Test #13:
score: 0
Runtime Error
input:
1978433568 49 481 0 6 0 7 0 12 0 13 0 16 0 19 0 20 0 33 0 35 0 37 0 44 0 46 1 2 1 9 1 10 1 15 1 17 1 25 1 30 1 31 1 34 2 20 2 32 2 34 2 40 2 46 2 48 1 3 3 6 3 8 3 12 3 15 3 22 3 25 3 28 3 31 3 38 3 45 3 48 1 4 3 4 4 9 4 11 4 18 4 20 4 21 4 28 4 29 4 30 4 32 4 41 4 46 4 47 4 48 2 5 5 6 5 13 5 16 5 17...
output:
877694080 -1 49 49 49 49 49 0 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 -1 49 49 49 49 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 ...
result:
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 -1 0 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 2...
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 -1 0 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 2...
result:
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%