Submission #995611
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define ins insert
#define er erase
#define bg begin()
#define ed end()
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define files(name) fin(name".in"); fout(name".out")
#define enter cout << "\n"
#define space cout << " "
#define endl "\n"
#define fi(st,n) for (int i = (st); i <= (n); ++i)
#define fj(st,n) for (int j = (st); j <= (n); ++j)
#define fk(st,n) for (int k = (st); k <= (n); ++k)
#define fq(st,n) for (int q = (st); q <= (n); ++q)
#define fw(st,n) for (int w = (st); w <= (n); ++w)
#define ff(i, st, n) for (int (i) = (st); (i) <= (n); ++(i))
#define ei(st,n) for (int i = (st); i >= (n); --i)
#define ej(st,n) for (int j = (st); j >= (n); --j)
#define ek(st,n) for (int k = (st); k >= (n); --k)
#define ef(i, st, n) for (int (i) = (st); (i) >= (n); --(i))
#define ri(st,n) for (int i = (st); i < (n); ++i)
#define rj(st,n) for (int j = (st); j < (n); ++j)
#define rk(st,n) for (int k = (st); k < (n); ++k)
#define rq(st,n) for (int q = (st); q < (n); ++q)
#define rf(i, st, n) for (int (i) = (st); (i) < (n); ++(i))
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define y1 dsklmlvmd
typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int inf = (int)1e9;
const dbl eps = (dbl) 1e-8;
const int mod = (int) 10000007;
const int maxn = (int) 2 * 1e5 + 5;
//const dbl M_PI = (dbl)2 * (dbl)acos(0);
//cout<<fixed<<setprecision(10);
//srand(time(0));
int n;
pii a[maxn];
int l, x, t[maxn], ans;
set <pii> q;
int main() {
// fin("t.in");
sync;
cin >> n;
fi(1, n) {
cin >> a[i].X >> a[i].Y;
}
if (a[1].Y != a[2].X || a[1].Y == 0) {
cout << -1 << endl;
return 0;
}
l = a[1].Y;
sort(a + 3, a + n + 1);
x = 1;
for (int i = 3; i <= n; ++i) {
t[i] = 0;
if (a[i].X == x && a[i].Y == l - x) {
t[i] = 1;
++x;
if (x == l)
break;
}
}
if (x != l) {
cout << -1 << endl;
return 0;
}
fi(0, l) {
q.ins(mp(i, l - i));
}
ans = l;
for (int i = 3; i <= n; ++i) {
if (t[i])
continue;
if (a[i].X + a[i].Y < l) {
cout << -1 << endl;
return 0;
}
if (q.count(mp(a[i].X - 1, a[i].Y - 1))) {
++ans;
q.ins(a[i]);
continue;
}
if (q.count(mp(a[i].X - 1, a[i].Y)) || q.count(mp(a[i].X, a[i].Y - 1))) {
ans += 2;
q.ins(a[i]);
continue;
}
cout << -1 << endl;
return 0;
}
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
A - Distance Pairs |
User |
mHuman |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2898 Byte |
Status |
WA |
Exec Time |
66 ms |
Memory |
6144 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 |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
26 ms |
1408 KB |
01-02.txt |
AC |
20 ms |
1152 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 |
WA |
12 ms |
768 KB |
01-07.txt |
WA |
23 ms |
1408 KB |
01-08.txt |
WA |
22 ms |
1408 KB |
01-09.txt |
WA |
21 ms |
1408 KB |
01-10.txt |
WA |
18 ms |
1024 KB |
01-11.txt |
AC |
27 ms |
1408 KB |
01-12.txt |
AC |
27 ms |
1408 KB |
01-13.txt |
AC |
61 ms |
5760 KB |
01-14.txt |
AC |
51 ms |
6144 KB |
01-15.txt |
AC |
66 ms |
6144 KB |
01-16.txt |
AC |
17 ms |
1024 KB |
01-17.txt |
WA |
15 ms |
1024 KB |
01-18.txt |
AC |
18 ms |
1408 KB |
01-19.txt |
WA |
36 ms |
3584 KB |
01-20.txt |
WA |
48 ms |
5248 KB |
01-21.txt |
WA |
48 ms |
5248 KB |
01-22.txt |
WA |
40 ms |
3456 KB |
01-23.txt |
AC |
23 ms |
1408 KB |
01-24.txt |
AC |
22 ms |
1280 KB |
01-25.txt |
AC |
14 ms |
1024 KB |
01-26.txt |
AC |
15 ms |
1024 KB |
01-27.txt |
AC |
22 ms |
1152 KB |
01-28.txt |
AC |
22 ms |
1280 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 |