Submission #995666
Source Code Expand
#include <iostream> #include <fstream> #include <set> #include <map> #include <string> #include <vector> #include <bitset> #include <algorithm> #include <cstring> #include <cstdlib> #include <cmath> #include <cassert> #include <queue> #define mp make_pair #define pb push_back typedef long long ll; typedef long double ld; using namespace std; const int MX = 120000; int n; int a[MX]; int b[MX]; vector<int> go[MX]; set<pair<int, int> > ss; set<pair<int, int> > sst; set<pair<int, int> > ss2; set<pair<int, int> > ss2t; vector<pair<int, int> > ed; vector<int> vv; map<pair<int, int>, int> mm; void ex() { //if (n != 3) // assert(false); cout << -1 << "\n"; exit(0); } int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i] >> b[i]; if (a[0] != 0 || b[1] != 0) ex(); for (int i = 0; i < n; ++i) { go[a[i]].push_back(i); } if ((int)go[0].size() != 1) ex(); ss.insert(make_pair(b[0], 0)); ss2.insert(make_pair(b[0], 0)); for (int i = 0; i < n; ++i) mm[make_pair(a[i], b[i])] = 1; for (int i = 1; i < n; ++i) { sst.clear(); ss2t.clear(); for (int j: go[i]) { auto it = ss.lower_bound(make_pair(b[j] + 1, 0)); ss2t.insert(make_pair(b[j], j)); if (it != ss.end() && it->first == b[j] + 1) { ed.push_back(make_pair(j, it->second)); ss.erase(it); sst.insert(make_pair(b[j], j)); } else { auto it = ss2.lower_bound(make_pair(b[j] - 1, 0)); if (it != ss2.end() && it->first <= b[j] + 1) { if (it->first != b[j] - 1) sst.insert(make_pair(b[j], j)); ed.push_back(make_pair(j, it->second)); } else { ex(); } } } for (auto j: ss) vv.push_back(j.second); swap(ss, sst); swap(ss2, ss2t); } for (int j: vv) { if (j == 1) continue; int fl = 0; for (int d = -1; d <= 1; ++d) { if (mm.count(make_pair(a[j] + d, b[j] - 1))) { fl = 1; ed.push_back(make_pair(mm[make_pair(a[j] + d, b[j] - 1)], j)); break; } } if (!fl) { ex(); } } cout << ed.size() << "\n"; /*for (auto j: ed) { cout << j.first + 1 << " " << j.second + 1 << "\n"; }*/ return 0; }
Submission Info
Submission Time | |
---|---|
Task | A - Distance Pairs |
User | LHiC |
Language | C++14 (GCC 5.4.1) |
Score | 1500 |
Code Size | 2213 Byte |
Status | AC |
Exec Time | 143 ms |
Memory | 15604 KB |
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 | 117 ms | 12032 KB |
01-02.txt | AC | 52 ms | 4480 KB |
01-03.txt | AC | 5 ms | 3072 KB |
01-04.txt | AC | 5 ms | 3072 KB |
01-05.txt | AC | 6 ms | 3072 KB |
01-06.txt | AC | 45 ms | 6264 KB |
01-07.txt | AC | 87 ms | 5880 KB |
01-08.txt | AC | 87 ms | 6008 KB |
01-09.txt | AC | 84 ms | 6136 KB |
01-10.txt | AC | 80 ms | 8180 KB |
01-11.txt | AC | 80 ms | 5796 KB |
01-12.txt | AC | 80 ms | 5668 KB |
01-13.txt | AC | 121 ms | 12920 KB |
01-14.txt | AC | 126 ms | 14332 KB |
01-15.txt | AC | 122 ms | 14332 KB |
01-16.txt | AC | 72 ms | 9716 KB |
01-17.txt | AC | 105 ms | 15604 KB |
01-18.txt | AC | 103 ms | 15604 KB |
01-19.txt | AC | 123 ms | 12792 KB |
01-20.txt | AC | 133 ms | 11000 KB |
01-21.txt | AC | 143 ms | 11128 KB |
01-22.txt | AC | 118 ms | 8568 KB |
01-23.txt | AC | 88 ms | 6008 KB |
01-24.txt | AC | 83 ms | 5988 KB |
01-25.txt | AC | 52 ms | 3840 KB |
01-26.txt | AC | 53 ms | 3840 KB |
01-27.txt | AC | 53 ms | 4480 KB |
01-28.txt | AC | 87 ms | 5880 KB |
01-29.txt | AC | 5 ms | 3072 KB |
01-30.txt | AC | 5 ms | 3072 KB |
01-31.txt | AC | 5 ms | 3072 KB |
sample-01.txt | AC | 5 ms | 3072 KB |
sample-02.txt | AC | 5 ms | 3072 KB |