Submission #999988
Source Code Expand
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
map <pair<int, int>, int> mp;
map <pair<pair<int, int>, pair<int, int> >, int> mp2;
bool check(int a, int b, int da, int db) {
return mp.count(make_pair(a + da, b + db));
}
void add(int a, int b, int da, int db, int c) {
pair<int, int> p1 = make_pair(a, b);
pair<int, int> p2 = make_pair(a + da, b + db);
if (p1 > p2) swap(p1, p2);
mp2[make_pair(p1, p2)] = max(mp2[make_pair(p1, p2)], c);
}
int solve() {
int n, d, ans = 0, i;
map <pair<int, int>, int>::iterator it;
map <pair<pair<int, int>, pair<int, int> >, int>::iterator it2;
scanf("%d", &n);
for (i = 0; i < n; i++) {
int a, b;
scanf("%d %d", &a, &b);
if (i == 0) {
if (a != 0 || b == 0) return -1;
d = b;
} else if (i == 1) {
if (a != d || b != 0) return -1;
} else {
if (a == 0 || b == 0 || a + b < d) return -1;
}
mp[make_pair(a, b)]++;
}
for (it = mp.begin(); it != mp.end(); it++) {
int a = it->first.first;
int b = it->first.second;
int c = it->second;
if (a != 0) {
if (check(a, b, -1, 1)) {
add(a, b, -1, 1, c);
} else if (check(a, b, -1, -1)) {
add(a, b, -1, -1, c);
} else if (check(a, b, -1, 0)) {
add(a, b, -1, 0, c);
} else {
return -1;
}
}
if (b != 0) {
if (check(a, b, 1, -1)) {
add(a, b, 1, -1, c);
} else if (check(a, b, -1, -1)) {
add(a, b, -1, -1, c);
} else if (check(a, b, 0, -1)) {
add(a, b, 0, -1, c);
} else {
return -1;
}
}
}
for (it2 = mp2.begin(); it2 != mp2.end(); it2++) ans += it2->second;
return ans;
}
int main() {
printf("%d\n", solve());
return 0;
}
Submission Info
Submission Time |
|
Task |
A - Distance Pairs |
User |
kawatea |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2182 Byte |
Status |
WA |
Exec Time |
211 ms |
Memory |
12672 KB |
Compile Error
./Main.cpp: In function ‘int solve()’:
./Main.cpp:28:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.cpp:33:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &a, &b);
^
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 |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
2 ms |
256 KB |
01-02.txt |
AC |
2 ms |
256 KB |
01-03.txt |
AC |
2 ms |
256 KB |
01-04.txt |
AC |
2 ms |
256 KB |
01-05.txt |
WA |
3 ms |
256 KB |
01-06.txt |
WA |
11 ms |
256 KB |
01-07.txt |
WA |
29 ms |
896 KB |
01-08.txt |
WA |
29 ms |
896 KB |
01-09.txt |
WA |
22 ms |
384 KB |
01-10.txt |
WA |
18 ms |
256 KB |
01-11.txt |
WA |
25 ms |
512 KB |
01-12.txt |
WA |
24 ms |
512 KB |
01-13.txt |
AC |
208 ms |
12672 KB |
01-14.txt |
AC |
209 ms |
12672 KB |
01-15.txt |
AC |
211 ms |
12672 KB |
01-16.txt |
AC |
15 ms |
256 KB |
01-17.txt |
AC |
15 ms |
256 KB |
01-18.txt |
AC |
15 ms |
256 KB |
01-19.txt |
AC |
204 ms |
12672 KB |
01-20.txt |
WA |
106 ms |
11008 KB |
01-21.txt |
WA |
108 ms |
11136 KB |
01-22.txt |
WA |
69 ms |
5888 KB |
01-23.txt |
AC |
28 ms |
768 KB |
01-24.txt |
AC |
29 ms |
896 KB |
01-25.txt |
AC |
2 ms |
256 KB |
01-26.txt |
AC |
2 ms |
256 KB |
01-27.txt |
AC |
16 ms |
512 KB |
01-28.txt |
AC |
14 ms |
512 KB |
01-29.txt |
AC |
2 ms |
256 KB |
01-30.txt |
AC |
2 ms |
256 KB |
01-31.txt |
AC |
2 ms |
256 KB |
sample-01.txt |
AC |
2 ms |
256 KB |
sample-02.txt |
AC |
2 ms |
256 KB |