QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#570162 | #9241. Sphinx | chenxinyang2006 | 0 | 0ms | 0kb | C++20 | 2.6kb | 2024-09-17 14:24:27 | 2024-09-17 14:24:27 |
answer
#include "sphinx.h"
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
int n;
vector <int> G[255],ans;
int fa[255];
int fnd(int u){
if(fa[u] == u) return u;
return fa[u] = fnd(fa[u]);
}
void mrg(int u,int v){
u = fnd(u);v = fnd(v);
if(u == v) return;
fa[u] = v;
}
int test(vector <int> &C){
rep(u,1,n) fa[u] = u;
rep(u,1,n){
for(int v:G[u]){
if(C[u - 1] == C[v - 1]) mrg(u,v);
}
}
int result = 0;
rep(u,1,n) result += fa[u] == u;
return result;
}
int test(vector <int> C,int l,int r){
rep(u,1,l - 1) C[u - 1] = n;
rep(u,r + 1,n) C[u - 1] = n;
return test(C);
}
int query(vector <int> &C){
assert(SZ(C) == n);
int ret = perform_experiment(C);
// for(int c:C) printf("%d ",c);
// printf("ret=%d\n",ret);
return ret;
}
int query(vector <int> C,int l,int r){
rep(u,1,l - 1) C[u - 1] = n;
rep(u,r + 1,n) C[u - 1] = n;
return query(C);
}
void trans(int x,int y){
for(int &c:ans) if(c == x) c = y;
}
vector <int> find_colours(int N, vector<int> X,vector<int> Y) {
n = N;
rep(i,0,SZ(X) - 1){
X[i]++;Y[i]++;
G[X[i]].eb(Y[i]);G[Y[i]].eb(X[i]);
}
vector <int> C(n);
ans = vector<int>(n,n);
rep(u,1,n){
rep(v,1,u) C[v - 1] = -1;
rep(v,u + 1,n) C[v - 1] = n;
int bas = query(C);
ans[u - 1] = u;
/* printf("curans=\n");
rep(v,1,n) printf("%d ",ans[v - 1]);
printf("\n");*/
while(test(ans) != bas){
int l = 1,r = n,mid;
while(l != r){
mid = (l + r) >> 1;
if(test(ans,l,mid) > query(C,l,mid)) r = mid;
else l = mid + 1;
}
trans(ans[u - 1],ans[l - 1]);
}
}
return ans;
}
/*
g++ sphinx4.cpp grader.cpp -o grader4.exe -Wall -Wshadow -O2 -std=c++14
*/
詳細信息
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
1978433568 2 1 0 1 1978433568 2 1978433568 1 1978433568 2 1978433568 2 1978433568 2 1978433568 2 1978433568 2 1978433568 2 1978433568 2 1978433568 2 1978433568 2 1978433568 2 1978433568 2 1978433568 2 1978433568 2 1978433568 2 1978433568 2 1978433568 2 1978433568 2 1978433568 2 1978433568 2 19784335...
output:
877694080 -1 2 877694080 -1 -1 877694080 -1 2 877694080 -1 2 877694080 -1 2 877694080 -1 2 877694080 -1 2 877694080 -1 2 877694080 -1 2 877694080 -1 2 877694080 -1 2 877694080 -1 2 877694080 -1 2 877694080 -1 2 877694080 -1 2 877694080 -1 2 877694080 -1 2 877694080 -1 2 877694080 -1 2 877694080 -1 2...
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
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 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 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 -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 250...
result:
Subtask #5:
score: 0
Skipped
Dependency #1:
0%