Submission #996022
Source Code Expand
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
int N;
int A[100010], B[100010];
int solve() {
try {
rep (i, N) {
if ((A[i] == 0) != (i == 0)) throw 0;
if ((B[i] == 0) != (i == 1)) throw 0;
}
int D = B[0];
if (A[1] != D) throw 0;
map<pair<int, int>, int> cnt;
rep (i, N) cnt[mp(A[i], B[i])] += 1;
map<int, map<int, int>> taba;
rep (i, N) {
taba[A[i] + B[i]][A[i]] += 1;
}
for (int d = 0; d < D; ++d) {
if (taba.count(d)) throw 0;
}
int ans = N - 1;
for (auto &i : taba) {
int d = i.first;
map<int, int> &m = i.second;
int request = 0; // request from left
for (const auto &j : m) {
int a = j.first, b = d - a, c = j.second;
if (a > 0 && cnt[mp(a - 1, b - 1)] + cnt[mp(a - 1, b)] + cnt[mp(a - 1, b + 1)] == 0) {
throw 0;
}
int hige;
if (cnt[mp(a - 1, b - 1)]) hige = max(0, c - request);
else hige = 0;
c -= hige;
ans += max(0, request - c);
if (cnt[(mp(a + 1, b - 1))] > 0) {
request = c;
} else if (b > 0) {
if (cnt[mp(a - 1, b - 1)] + cnt[mp(a, b - 1)] + cnt[mp(a + 1, b - 1)] == 0) {
throw 0;
}
ans += c;
request = 0;
}
}
}
return ans;
} catch (...) {
return -1;
}
}
int main() {
scanf("%d", &N);
rep (i, N) {
scanf("%d%d", &A[i], &B[i]);
}
int ans1 = solve();
rep (i, N) swap(A[i], B[i]);
swap(A[0], A[1]);
swap(B[0], B[1]);
int ans2 = solve();
assert(ans1 == ans2);
printf("%d\n", ans1);
return 0;
}
Submission Info
Submission Time |
|
Task |
A - Distance Pairs |
User |
iwiwi |
Language |
C++14 (GCC 5.4.1) |
Score |
1500 |
Code Size |
2357 Byte |
Status |
AC |
Exec Time |
469 ms |
Memory |
46336 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:92:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
^
./Main.cpp:94:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &A[i], &B[i]);
^
Judge Result
Set Name |
sample |
All |
Score / Max Score |
0 / 0 |
1500 / 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 |
211 ms |
18816 KB |
01-02.txt |
AC |
32 ms |
1024 KB |
01-03.txt |
AC |
2 ms |
256 KB |
01-04.txt |
AC |
2 ms |
256 KB |
01-05.txt |
AC |
3 ms |
256 KB |
01-06.txt |
AC |
15 ms |
768 KB |
01-07.txt |
AC |
62 ms |
2176 KB |
01-08.txt |
AC |
61 ms |
1792 KB |
01-09.txt |
AC |
38 ms |
1152 KB |
01-10.txt |
AC |
26 ms |
1024 KB |
01-11.txt |
AC |
51 ms |
1792 KB |
01-12.txt |
AC |
48 ms |
1664 KB |
01-13.txt |
AC |
453 ms |
40320 KB |
01-14.txt |
AC |
280 ms |
24448 KB |
01-15.txt |
AC |
469 ms |
46336 KB |
01-16.txt |
AC |
18 ms |
1024 KB |
01-17.txt |
AC |
18 ms |
1024 KB |
01-18.txt |
AC |
19 ms |
1024 KB |
01-19.txt |
AC |
394 ms |
33024 KB |
01-20.txt |
AC |
237 ms |
14080 KB |
01-21.txt |
AC |
239 ms |
14208 KB |
01-22.txt |
AC |
156 ms |
7808 KB |
01-23.txt |
AC |
56 ms |
1664 KB |
01-24.txt |
AC |
61 ms |
1876 KB |
01-25.txt |
AC |
16 ms |
1024 KB |
01-26.txt |
AC |
17 ms |
1024 KB |
01-27.txt |
AC |
17 ms |
1024 KB |
01-28.txt |
AC |
17 ms |
1024 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 |