QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#358836#6570. Who Watches the Watchmen?Delay_for_five_minutesWA 546ms4836kbC++207.1kb2024-03-20 02:02:462024-03-20 02:02:46

Judging History

你现在查看的是最新测评结果

  • [2024-03-20 02:02:46]
  • 评测
  • 测评结果:WA
  • 用时:546ms
  • 内存:4836kb
  • [2024-03-20 02:02:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
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;
}
typedef pair<ll,ll> pll ;
pair<pll,pll> solve(array<int,3> u1,array<int,3> u2) {
    ll a = 1LL * u1[2] * (-u2[0]) + 1LL * u2[2] * u1[0] ; /// a/b
    ll b = 1LL * u1[1] * (-u2[0]) + 1LL * u2[1] * u1[0] ;
    ll g = __gcd(a , b) ; 
    if(g) {
        a /= g;b /= g;
    }
    if(b < 0) a *= -1 , b *= -1;
    ll c = 1LL * u1[2] * (-u2[1]) + 1LL * u2[2] * u1[1] ; /// c/d
    ll d = 1LL * u1[0] * (-u2[1]) + 1LL * u2[0] * u1[1] ;
    g = __gcd(c , d) ; 
    if(g) {
        c /= g;d /= g;
    }
    if(d < 0) c *= -1 , d *= -1;
    return {(pll){c,d},(pll){a,b}} ;
}
bool zero(pll &A) {
    return (A.first == 0 && A.second == 0) ;
}
int get_ans(int i,int j,int k) {
    if(gx(i , j) && gx(k , j)) return 2;
    if(gx(i , j) || gx(k , j)) return 1;
    if(par(i , k)) return 1;
    // printf("chk %d %d %d\n",i,j,k) ;
    pair<pll,pll> a1 = solve({t[i][0] , t[k][0] , p[j][0] - p[k][0]} , {t[i][1] , t[k][1] , p[j][1] - p[k][1]}) ;
    // printf("s1 %lld %lld : %lld %lld\n",a1.first.first,a1.first.second,a1.second.first,a1.second.second) ;
    if(a1.first.first < 0 || a1.second.first < 0) return 1;
    pair<pll,pll> a2 = solve({t[i][0] , t[k][0] , p[j][0] - p[k][0]} , {t[i][2] , t[k][2] , p[j][2] - p[k][2]}) ;
    // printf("s1 %lld %lld : %lld %lld\n",a1.first.first,a1.first.second,a1.second.first,a1.second.second) ;
    // printf("s2 %lld %lld : %lld %lld\n",a2.first.first,a2.first.second,a2.second.first,a2.second.second) ;
    if((a2.first != a1.first && !zero(a2.first) && !zero(a1.first)) || (a2.second != a1.second && !zero(a2.second) && !zero(a2.second))) return 1;
    // printf("ret 0\n") ;
    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];
                // printf("%d %d %d : %d %d\n",i,j,k,cur1,ad) ;
                sol = min(sol , cur1 + get_ans(i , id[v[j]] , id[v[k]]) + ad) ;
                sol = min(sol , cur2 + get_ans(i , id[v[k]] , id[v[j]]) + 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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3780kb

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: 3592kb

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: 3456kb

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: 3540kb

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: 3656kb

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: 3588kb

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: 3772kb

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: 3460kb

input:

1
0 0 0 3 1 4

output:

-1

result:

ok single line: '-1'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3612kb

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: 3536kb

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: 3844kb

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: 3788kb

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: 3776kb

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: 3660kb

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: 3532kb

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: 3492kb

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: 539ms
memory: 3792kb

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: 502ms
memory: 3488kb

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: 546ms
memory: 3756kb

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: 3744kb

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: 3544kb

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: 3836kb

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: 3744kb

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: 3740kb

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: 3476kb

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: 0
Accepted
time: 0ms
memory: 3572kb

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:

1001

result:

ok single line: '1001'

Test #27:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

17
0 0 0 0 0 1
0 1 0 0 0 1
0 2 0 0 0 1
0 3 0 0 0 1
0 4 0 0 0 1
0 -1 0 0 0 1
0 -2 0 0 0 1
0 -3 0 0 0 1
0 -4 0 0 0 1
1 3 0 0 0 1
2 3 0 0 0 1
-1 3 0 0 0 1
-2 3 0 0 0 1
1 -3 0 0 0 1
2 -3 0 0 0 1
-1 -3 0 0 0 1
-2 -3 0 0 0 1

output:

17

result:

ok single line: '17'

Test #28:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

17
0 0 0 0 4 0
0 1 0 0 -1 0
0 2 0 0 -2 0
0 3 0 0 -3 0
0 4 0 0 -4 0
0 -1 0 0 1 0
0 -2 0 0 2 0
0 -3 0 0 3 0
0 -4 0 0 4 0
1 3 0 -1 -3 0
2 3 0 -1 -2 0
-1 3 0 1 -3 0
-2 3 0 2 -3 0
1 -3 0 -1 3 0
2 -3 0 -2 3 0
-1 -3 0 1 3 0
-2 -3 0 2 3 0

output:

10

result:

ok single line: '10'

Test #29:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

17
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 2 -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
1 3 0 -1 0 0
2 3 0 -1 0 0
-1 3 0 -1 0 0
-2 3 0 4 -6 0
1 -3 0 -1 0 0
2 -3 0 -1 0 0
-1 -3 0 -1 0 0
-2 -3 0 2 -1 0

output:

3

result:

ok single line: '3'

Test #30:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

5
0 0 0 1 1 1
0 0 1 0 0 1
0 0 2 0 0 1
0 0 3 0 0 1
0 0 4 0 -1 1

output:

1001

result:

ok single line: '1001'

Test #31:

score: 0
Accepted
time: 139ms
memory: 4836kb

input:

500
-455212 958307 274912 -88656 390687 881409
-498879 -623821 322766 -916023 347922 541726
-594515 -554311 -413504 -881701 -506880 -144667
658945 -503396 791805 314816 -830920 -769486
-200847 845218 468338 -166468 -49854 -287877
-820402 914874 916800 258029 -210000 -296727
702016 -389491 -31529 -52...

output:

499

result:

ok single line: '499'

Test #32:

score: -100
Wrong Answer
time: 0ms
memory: 3536kb

input:

3
1000000 -1 -1 -1000000 -999999 -999999
-1 1000000 -1 101 -101 0
100 999899 -1 999999 1000000 999999

output:

1001

result:

wrong answer 1st lines differ - expected: '1000', found: '1001'