QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#358824 | #6570. Who Watches the Watchmen? | Delay_for_five_minutes | WA | 455ms | 3868kb | C++20 | 5.4kb | 2024-03-20 01:24:09 | 2024-03-20 01:24:10 |
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;
}
bool par(int i,int j) {
if(1LL * t[i][0] * t[j][1] == 1LL * t[i][1] * t[j][0] && 1LL * t[i][1] * t[j][2] == 1LL * t[i][2] * t[j][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];
});
if(n % 2 == 0) {
int ans = 0;
for(int i = 1;i <= n;i += 2) {
ans += (2 - check(id[i] , id[i + 1]) - check(id[i + 1] , id[i])) ;
}
cout << ans << '\n' ;
return ;
}
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]]) + (par(id[v[k]] , i)||gx(id[v[k]] , i)) + ad) ;
sol = min(sol , cur2 + gx(i , id[v[j]]) + (par(id[v[j]] , i)||gx(id[v[j]] , i)) + ad) ;
// printf("%d %d %d : %d\n",i,j,k , sol) ;
}
}
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()) ;
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: 0ms
memory: 3632kb
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: 0ms
memory: 3648kb
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: 0
Accepted
time: 0ms
memory: 3496kb
input:
3 0 0 0 1 0 0 1 1 1 1 0 0 2 2 2 1 0 0
output:
1002
result:
ok single line: '1002'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
3 0 0 0 1 1 1 1 1 1 1 0 0 2 2 2 1 0 0
output:
1001
result:
ok single line: '1001'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
3 0 0 0 1 0 0 1 1 1 1 0 0 2 2 2 -1 -1 -1
output:
1001
result:
ok single line: '1001'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
3 0 0 0 1 0 0 1 1 1 1 2 2 2 2 2 -1 -1 -1
output:
1000
result:
ok single line: '1000'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
3 0 0 0 1 0 0 1 1 1 1 2 2 2 2 2 1 1 1
output:
1001
result:
ok single line: '1001'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
1 0 0 0 3 1 4
output:
-1
result:
ok single line: '-1'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
4 0 0 0 1 1 1 1 0 0 -1 0 0 1 1 1 0 -1 0 1 0 1 0 1 0
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
500 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 7 0 0 1 0 0 8 0 0 1 0 0 9 0 0 1 0 0 10 0 0 -1 0 0 11 0 0 -1 0 0 12 0 0 1 0 0 13 0 0 -1 0 0 14 0 0 1 0 0 15 0 0 1 0 0 16 0 0 1 0 0 17 0 0 -1 0 0 18 0 0 -1 0 0 19 0 0 -1 0 0 20 0 0 -1 0 0 21 0 0 1 0 0 22 0 0 1 0 0...
output:
250
result:
ok single line: '250'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3828kb
input:
500 0 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 7 0 0 1 0 0 8 0 0 1 0 0 9 0 0 1 0 0 10 0 0 -1 0 0 11 0 0 -1 0 0 12 0 0 1 0 0 13 0 0 -1 0 0 14 0 0 1 0 0 15 0 0 1 0 0 16 0 0 1 0 0 17 0 0 -1 0 0 18 0 0 -1 0 0 19 0 0 -1 0 0 20 0 0 -1 0 0 21 0 0 1 0 0 22 0 0 1 0...
output:
250
result:
ok single line: '250'
Test #12:
score: 0
Accepted
time: 1ms
memory: 3860kb
input:
500 0 0 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 7 0 0 1 0 0 8 0 0 1 0 0 9 0 0 1 0 0 10 0 0 -1 0 0 11 0 0 -1 0 0 12 0 0 1 0 0 13 0 0 -1 0 0 14 0 0 1 0 0 15 0 0 1 0 0 16 0 0 1 0 0 17 0 0 -1 0 0 18 0 0 -1 0 0 19 0 0 -1 0 0 20 0 0 -1 0 0 21 0 0 1 0 0 22 0 0 1...
output:
250
result:
ok single line: '250'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
5 1 0 0 1 -1 0 2 0 0 0 1 0 3 0 0 -1 0 0 4 0 0 -1 0 0 5 0 0 -1 0 0
output:
1000
result:
ok single line: '1000'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
5 1 0 0 1 0 0 2 0 0 1 0 0 3 0 0 1 0 0 4 0 0 0 1 0 5 0 0 -1 -1 0
output:
1000
result:
ok single line: '1000'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
6 0 1 0 1 0 0 0 2 0 0 2 0 0 3 0 0 3 0 0 4 0 0 4 0 0 5 0 0 5 0 0 6 0 0 6 0
output:
4
result:
ok single line: '4'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
9 1 0 0 1 0 0 2 0 0 1 0 0 3 0 0 1 0 0 0 1 0 0 1 0 0 2 0 0 1 0 0 3 0 0 1 0 0 0 1 0 0 1 0 0 2 0 0 1 0 0 3 0 0 1
output:
3
result:
ok single line: '3'
Test #17:
score: 0
Accepted
time: 432ms
memory: 3840kb
input:
499 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 7 0 0 1 0 0 8 0 0 1 0 0 9 0 0 1 0 0 10 0 0 -1 0 0 11 0 0 -1 0 0 12 0 0 1 0 0 13 0 0 -1 0 0 14 0 0 1 0 0 15 0 0 1 0 0 16 0 0 1 0 0 17 0 0 -1 0 0 18 0 0 -1 0 0 19 0 0 -1 0 0 20 0 0 -1 0 0 21 0 0 1 0 0 22 0 0 1 0 0...
output:
1220
result:
ok single line: '1220'
Test #18:
score: 0
Accepted
time: 411ms
memory: 3580kb
input:
499 0 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 7 0 0 1 0 0 8 0 0 1 0 0 9 0 0 1 0 0 10 0 0 -1 0 0 11 0 0 -1 0 0 12 0 0 1 0 0 13 0 0 -1 0 0 14 0 0 1 0 0 15 0 0 1 0 0 16 0 0 1 0 0 17 0 0 -1 0 0 18 0 0 -1 0 0 19 0 0 -1 0 0 20 0 0 -1 0 0 21 0 0 1 0 0 22 0 0 1 0...
output:
1220
result:
ok single line: '1220'
Test #19:
score: 0
Accepted
time: 455ms
memory: 3580kb
input:
499 0 0 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 7 0 0 1 0 0 8 0 0 1 0 0 9 0 0 1 0 0 10 0 0 -1 0 0 11 0 0 -1 0 0 12 0 0 1 0 0 13 0 0 -1 0 0 14 0 0 1 0 0 15 0 0 1 0 0 16 0 0 1 0 0 17 0 0 -1 0 0 18 0 0 -1 0 0 19 0 0 -1 0 0 20 0 0 -1 0 0 21 0 0 1 0 0 22 0 0 1...
output:
1220
result:
ok single line: '1220'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
5 0 0 0 0 -1 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
output:
1001
result:
ok single line: '1001'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
5 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 0 1 0
output:
1001
result:
ok single line: '1001'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
5 0 0 0 1 0 0 1 0 0 1 0 0 2 0 0 0 -1 0 3 0 0 1 0 0 4 0 0 -1 0 0
output:
1001
result:
ok single line: '1001'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
5 0 0 0 1 0 0 1 0 0 -1 0 0 2 0 0 1 0 0 3 0 0 0 -1 0 4 0 0 1 0 0
output:
1001
result:
ok single line: '1001'
Test #24:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
5 0 0 0 1 1 0 1 0 0 1 0 0 2 0 0 1 0 0 3 0 0 1 0 0 4 0 0 -1 -1 0
output:
1001
result:
ok single line: '1001'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
5 0 0 0 1 1 0 1 0 0 1 0 0 2 0 0 1 0 0 3 0 0 1 0 0 4 0 0 1 1 0
output:
1001
result:
ok single line: '1001'
Test #26:
score: -100
Wrong Answer
time: 0ms
memory: 3632kb
input:
5 0 0 0 5 -1 0 1 0 0 1 0 0 2 0 0 1 0 0 3 0 0 1 0 0 4 0 0 1 -1 0
output:
1000
result:
wrong answer 1st lines differ - expected: '1001', found: '1000'