Submission #2483906
Source Code Expand
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
int N;
int A[100000], B[100000];
map<P, bool> exist;
map<P, int> CA, CB;
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> N;
rep(i, N) cin >> A[i] >> B[i];
int zero_a = 0, zero_b = 0;
rep(i, N) zero_a += A[i]==0, zero_b += B[i]==0;
if (A[0] != 0 || B[1] != 0 || zero_a != 1 || zero_b != 1) {
cout << -1 << "\n";
return 0;
}
rep(i, N) exist[P(A[i], B[i])] = true;
rep(i, N) {
int a = A[i], b = B[i];
if (a > 0 && !exist[P(a-1, b-1)] && !exist[P(a-1, b)] && !exist[P(a-1, b+1)]) {
cout << -1 << "\n";
return 0;
}
if (b > 0 && !exist[P(a-1, b-1)] && !exist[P(a, b-1)] && !exist[P(a+1, b-1)]) {
cout << -1 << "\n";
return 0;
}
}
int sum = 0;
rep(i, N) {
int a = A[i], b = B[i];
if (exist[P(a-1, b-1)]) sum++;
else {
//cout<<"("<<a<<","<<b<<")\n";
if (a > 0) CA[P(a, b)]++;
if (b > 0) CB[P(a, b)]++;
}
}
for (auto &p : CA) {
int a = p._1._1, b = p._1._2;
int num = min(p._2, CB[P(a-1, b+1)]);
p._2 -= num;
CB[P(a-1, b+1)] -= num;
//cout<<"("<<a<<","<<b<<")<->("<<a-1<<","<<b+1<<") * "<<num<<"\n";
sum += num;
}
for (auto p : CA) sum += p._2;
for (auto p : CB) sum += p._2;
cout << sum << "\n";
return 0;
}
Submission Info
Submission Time |
|
Task |
A - Distance Pairs |
User |
funcsr |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1924 Byte |
Status |
WA |
Exec Time |
354 ms |
Memory |
32256 KB |
Judge Result
Set Name |
sample |
All |
Score / Max Score |
0 / 0 |
0 / 1500 |
Status |
|
|
Set Name |
Test Cases |
sample |
sample-01.txt, sample-02.txt |
All |
sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, sample-01.txt, sample-02.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
52 ms |
7296 KB |
01-02.txt |
AC |
17 ms |
1024 KB |
01-03.txt |
AC |
1 ms |
256 KB |
01-04.txt |
AC |
1 ms |
256 KB |
01-05.txt |
AC |
2 ms |
256 KB |
01-06.txt |
AC |
12 ms |
768 KB |
01-07.txt |
WA |
50 ms |
1408 KB |
01-08.txt |
WA |
50 ms |
1408 KB |
01-09.txt |
WA |
33 ms |
1152 KB |
01-10.txt |
AC |
22 ms |
1024 KB |
01-11.txt |
AC |
42 ms |
1280 KB |
01-12.txt |
AC |
39 ms |
1152 KB |
01-13.txt |
AC |
140 ms |
9472 KB |
01-14.txt |
AC |
354 ms |
32256 KB |
01-15.txt |
AC |
112 ms |
7296 KB |
01-16.txt |
AC |
16 ms |
1024 KB |
01-17.txt |
AC |
19 ms |
1024 KB |
01-18.txt |
AC |
18 ms |
1024 KB |
01-19.txt |
AC |
228 ms |
19840 KB |
01-20.txt |
WA |
210 ms |
16384 KB |
01-21.txt |
WA |
212 ms |
16512 KB |
01-22.txt |
WA |
155 ms |
9216 KB |
01-23.txt |
AC |
32 ms |
1408 KB |
01-24.txt |
AC |
38 ms |
1408 KB |
01-25.txt |
AC |
14 ms |
1024 KB |
01-26.txt |
AC |
14 ms |
1024 KB |
01-27.txt |
AC |
14 ms |
1024 KB |
01-28.txt |
AC |
14 ms |
1024 KB |
01-29.txt |
AC |
1 ms |
256 KB |
01-30.txt |
AC |
1 ms |
256 KB |
01-31.txt |
AC |
1 ms |
256 KB |
sample-01.txt |
AC |
1 ms |
256 KB |
sample-02.txt |
AC |
1 ms |
256 KB |