QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#358811 | #6570. Who Watches the Watchmen? | Delay_for_five_minutes | WA | 1ms | 3600kb | C++20 | 5.0kb | 2024-03-20 01:13:59 | 2024-03-20 01:14:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int INF = 1e7;
const int N = 505 ;
int n ;
array<int,3> p[505] , t[505];
int e[N][N];
int w[N*2],s[N*2],pre[N*2],mat[N*2],cur,pn;
bool vis[N*2];
void bfs(int x){
memset(vis,0,sizeof(vis));
memset(s,63,sizeof(s));
memset(pre,0,sizeof(pre));
cur=pn=0,mat[0]=x;
while(1){
x=mat[cur];
int dis=INF;
vis[cur]=1;
for(int i=n+1;i<=2*n;++i){
if(vis[i])continue;
int tmp=w[i]+w[x]-e[x][i-n];
if(tmp<s[i])s[i]=tmp,pre[i]=cur;
if(s[i]<dis)dis=s[i],pn=i;
}
w[mat[0]]-=dis,w[0]+=dis;
for(int i=n+1;i<=2*n;++i){
if(vis[i])w[i]+=dis,w[mat[i]]-=dis;
else s[i]-=dis;
}
cur=pn;
if(!mat[cur])break;
}
while(cur){
mat[cur]=mat[pre[cur]];
cur=pre[cur];
}
}
int KM(){
for(int i=1;i<=n;++i)bfs(i);
int res=0;
for(int i=1;i<=n;++i)if(mat[i+n])res+=e[mat[i+n]][i];
return res;
}
int sgn(int x) {
if(x > 0) return 1;
else if(x == 0) return 0;
return -1;
}
bool check(int i,int j) { ///i指向j
array<int,3> delta = {p[j][0] - p[i][0] , p[j][1] - p[i][1] , p[j][2] - p[i][2]} ;
if(sgn(delta[0]) == sgn(t[i][0]) & sgn(delta[1]) == sgn(t[i][1]) && sgn(delta[2]) == sgn(t[i][2]) ) {
if(1LL * delta[0] * t[i][1] == 1LL * delta[1] * t[i][0] && 1LL * delta[1] * t[i][2] == 1LL * delta[2] * t[i][1]) return 1;
return 0;
}
return 0;
}
bool gx(int i,int j) {
array<int,3> delta = {p[j][0] - p[i][0] , p[i][1] - p[j][1] , p[i][2] - p[j][2]} ;
if(1LL * delta[0] * t[i][1] == 1LL * delta[1] * t[i][0] && 1LL * delta[1] * t[i][2] == 1LL * delta[2] * t[i][1]) return 1;
return 0;
}
int id[505];
void work() {
int ans = 1e7;
for(int i = 1;i <= n;i++) id[i] = i;
sort(id + 1 , id + n + 1 , [&](int x,int y) {
if(p[x][0] != p[y][0]) return p[x][0] < p[y][0] ;
if(p[x][1] != p[y][1]) return p[x][1] < p[y][1] ;
return p[x][2] < p[y][2];
});
for(int i = 1;i <= n;i++) {
vector<int> v;
for(int j = 1;j <= n;j++) {
if(j != i ) v.push_back(j) ;
}
vector<int> pre(v.size()) , suf(v.size());
for(int i = 0;i + 1 < v.size();i += 2) {
if(i) pre[i + 1] = pre[i - 1] ;
pre[i + 1] += 2 - (check(id[v[i]] , id[v[i + 1]]) + check(id[v[i + 1]] , id[v[i]]) );
}
for(int i = v.size() - 1;i - 1 >= 0;i -= 2) {
if(i != v.size() - 1) suf[i - 1] = suf[i + 1];
suf[i - 1] += 2 - (check(id[v[i]] , id[v[i - 1]]) + check(id[v[i - 1]] , id[v[i]])) ;
}
int sol = 1e7;
for(int j = 0;j < v.size();j++) {
int cur1 = 0 , cur2 = 0;
if(j % 2 == 1) continue ;
for(int k = j + 1;k < v.size();k++) {
cur1 += 1 - check(id[v[k - 1]] , id[v[k]]) ;
cur2 += 1 - check(id[v[k]] , id[v[k - 1]]) ;
// printf("%d %d %d\n",j,k,v.size()) ;
if((v.size() - k) % 2 == 0) continue ;
// printf("here\n") ;
int ad = 0;
if(j > 0) ad += pre[j - 1] ;
if(k < v.size() - 1) ad += suf[k + 1];
sol = min(sol , cur1 + gx(i , id[v[k]]) + gx(id[v[k]] , i) + ad) ;
sol = min(sol , cur2 + gx(i , id[v[j]]) + gx(id[v[j]] , i) + ad) ;
}
}
ans = min(ans , sol) ;
}
cout << (ans + 1000) << '\n' ;
return ;
}
int main() {
cin >> n;
for(int i = 1;i <= n;i++) {
for(int j = 0;j < 3;j++) cin >> p[i][j];
for(int j = 0;j < 3;j++) cin >> t[i][j];
}
if(n == 1) {
cout << -1 << '\n' ; return 0;
}
if(n == 2) {
int ans = check(1 , 2) + check(2 , 1);
cout << (2-ans) << '\n' ; return 0;
}
for(int i = n;i >= 1;i--) {
for(int j = 0;j < 3;j++) p[i][j] -= p[1][j] ;
}
bool ff = 1;
for(int i = 3;i <= n;i++) {
if(!(1LL * p[i][0] * p[2][1] == 1LL * p[i][1] * p[2][0] && 1LL * p[i][1] * p[2][2] == 1LL * p[i][2] * p[2][1])) {ff = 0;break ;}
}
if(ff) {
work() ; return 0;
}
for(int i = 1;i <= n;i++) {
map<array<int,3> , vector<pii> > mp;
e[i][i] = 1e7;
for(int j = 1;j <= n;j++) {
if(i == j) continue ;
array<int,3> ar = {p[j][0] - p[i][0] , p[j][1] - p[i][1] , p[j][2] - p[i][2]} ;
int g = abs(ar[0]) ; g = __gcd(g , abs(ar[1])) ; g = __gcd(g , abs(ar[2])) ;
ar[0] /= g ; ar[1] /= g ; ar[2] /= g;
mp[ar].push_back({g , j}) ;
}
for(auto &[u,v] : mp) {
sort(v.begin() , v.end() , [&](pii x,pii y){return x > y;}) ;
e[i][v[0].second] = 1 - check(i , v[0].second) ;
for(int j = 1;j < v.size();j++) e[i][v[j].second] = 1e7;
}
for(int j = 1;j <= n;j++ ) {e[i][j] *= -1 ; }
// printf("\n") ;
}
cout << -KM() << '\n' ;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3544kb
input:
7 0 0 0 1 0 0 1 0 0 -1 0 0 2 0 0 1 0 0 3 0 0 1 0 0 4 0 0 1 0 0 5 0 0 1 0 0 6 0 0 -1 0 0
output:
1002
result:
ok single line: '1002'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
4 66 45 10 73 39 36 95 14 26 47 84 59 14 66 89 89 36 78 16 27 94 79 24 24
output:
4
result:
ok single line: '4'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3568kb
input:
3 0 0 0 1 0 0 1 1 1 1 0 0 2 2 2 1 0 0
output:
1001
result:
wrong answer 1st lines differ - expected: '1002', found: '1001'