QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#483429#8708. PortalWansur1 9ms18868kbC++231.6kb2024-07-18 17:08:082024-07-18 17:08:09

Judging History

This is the latest submission verdict.

  • [2024-07-18 17:08:09]
  • Judged
  • Verdict: 1
  • Time: 9ms
  • Memory: 18868kb
  • [2024-07-18 17:08:08]
  • Submitted

answer

#include <bits/stdc++.h>
#define ent '\n'
#define f first
#define s second
#define int long long

using namespace std;
typedef long long ll;
const int maxn = 1e6 + 12;
const int mod = 1e9 + 7;

int x[maxn], y[maxn];
int p[maxn];
int n, m, s;

int get(int x){
    if(p[x] == x) return x;
    return p[x] = get(p[x]);
}

int pos(int x, int y){
    return x * 1003 + y;
}

void solve(){
    cin >> n;
    if(n <= 2){
        cout << "-1\n";
        return;
    }
    int mnx = 1e9, mny = 1e9;
    for(int i=1;i<=n;i++){
        cin >> x[i] >> y[i];
        x[i] += 305, y[i] += 305;
        mnx = min(mnx, x[i]);
        mny = min(mny, y[i]);
    }
    for(int i=0;i<1000;i++){
        for(int j=0;j<1000;j++){
            p[i*1003 + j] = i * 1003 + j;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            for(int dx=-150;dx<=150;dx++){
                for(int dy=-150;dy<=150;dy++){
                    p[get(pos(x[i] + dx, y[i] + dy))] = get(pos(x[j] + dx, y[j] + dy));
                }
            }
        }
    }
    set<int> s, t;
    for(int i=mnx;i<=mnx+100;i++){
        for(int j=mny;j<=mny+100;j++){
            s.insert(get(pos(i, j)));
        }
    }
    for(int i=mnx-100;i<=mnx+100;i++){
        for(int j=mny-100;j<=mny+100;j++){
            t.insert(get(pos(i, j)));
        }
    }
    if(s.size() != t.size()){
        cout << "-1\n";
    }
    else{
        cout << s.size() << ent;
    }
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 1
Accepted

Test #1:

score: 1
Accepted
time: 0ms
memory: 3580kb

input:

1
1 -1

output:

-1

result:

ok single line: '-1'

Test #2:

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

input:

2
-455833 -283524
427847 159281

output:

-1

result:

ok single line: '-1'

Test #3:

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

input:

2
52420 -46322
-192914 87067

output:

-1

result:

ok single line: '-1'

Test #4:

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

input:

2
52446 -20773
179773 174566

output:

-1

result:

ok single line: '-1'

Test #5:

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

input:

2
-229012 -260770
-174790 -69382

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

2
-127294 418312
211124 37002

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

2
-129173 516840
46821 -187136

output:

-1

result:

ok single line: '-1'

Test #8:

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

input:

2
-90088 -7423
234488 19625

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

2
-48105 256695
15135 -80585

output:

-1

result:

ok single line: '-1'

Test #10:

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

input:

2
-251318 79061
182792 -129183

output:

-1

result:

ok single line: '-1'

Test #11:

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

input:

2
784850 417677
-217245 -460999

output:

-1

result:

ok single line: '-1'

Test #12:

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

input:

2
31270 410692
713271 917276

output:

-1

result:

ok single line: '-1'

Test #13:

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

input:

1
230862 -785444

output:

-1

result:

ok single line: '-1'

Test #14:

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

input:

2
222814 -279784
-73657 59849

output:

-1

result:

ok single line: '-1'

Test #15:

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

input:

2
72171 -104186
201480 105502

output:

-1

result:

ok single line: '-1'

Test #16:

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

input:

2
-17727 -27151
69235 15029

output:

-1

result:

ok single line: '-1'

Test #17:

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

input:

2
-44049 96618
173806 -21489

output:

-1

result:

ok single line: '-1'

Test #18:

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

input:

2
-81268 -53452
329866 -163275

output:

-1

result:

ok single line: '-1'

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #19:

score: 0
Wrong Answer
time: 9ms
memory: 18868kb

input:

3
1 1
1 3
3 2

output:

-1

result:

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

Subtask #3:

score: 0
Runtime Error

Test #40:

score: 0
Runtime Error

input:

99840
-359536 735499
-710626 400619
-468266 -282389
-192706 43659
204034 -543669
-100576 -749013
-118006 -283125
-341276 405771
560934 835595
-923936 506603
239724 956299
-680746 -737237
286204 982795
-847576 -282389
-949666 986475
996684 -429589
672984 -133717
140954 696491
-879116 -442837
985064 7...

output:


result:


Subtask #4:

score: 0
Wrong Answer

Test #59:

score: 0
Wrong Answer
time: 3ms
memory: 18460kb

input:

5
0 0
1 0
-1 0
0 1
0 -1

output:

-1

result:

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

Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%