Submission #995639
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->second <= b[j] + 1) { if (it->second != 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 | 0 |
Code Size | 2211 Byte |
Status | WA |
Exec Time | 213 ms |
Memory | 14332 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 | RE | 213 ms | 12032 KB |
01-02.txt | RE | 157 ms | 4608 KB |
01-03.txt | AC | 5 ms | 3072 KB |
01-04.txt | WA | 4 ms | 3072 KB |
01-05.txt | RE | 110 ms | 3072 KB |
01-06.txt | RE | 139 ms | 3840 KB |
01-07.txt | RE | 172 ms | 4736 KB |
01-08.txt | RE | 171 ms | 4736 KB |
01-09.txt | RE | 163 ms | 4352 KB |
01-10.txt | RE | 161 ms | 4480 KB |
01-11.txt | RE | 169 ms | 4480 KB |
01-12.txt | RE | 171 ms | 4480 KB |
01-13.txt | RE | 212 ms | 11776 KB |
01-14.txt | AC | 123 ms | 14332 KB |
01-15.txt | RE | 213 ms | 13184 KB |
01-16.txt | RE | 153 ms | 4476 KB |
01-17.txt | WA | 71 ms | 9716 KB |
01-18.txt | WA | 72 ms | 9716 KB |
01-19.txt | RE | 212 ms | 11648 KB |
01-20.txt | RE | 211 ms | 9856 KB |
01-21.txt | RE | 213 ms | 9984 KB |
01-22.txt | RE | 197 ms | 7424 KB |
01-23.txt | RE | 172 ms | 4736 KB |
01-24.txt | RE | 170 ms | 4736 KB |
01-25.txt | RE | 157 ms | 3840 KB |
01-26.txt | RE | 157 ms | 3840 KB |
01-27.txt | RE | 160 ms | 4480 KB |
01-28.txt | RE | 169 ms | 4736 KB |
01-29.txt | RE | 112 ms | 3072 KB |
01-30.txt | RE | 113 ms | 3072 KB |
01-31.txt | RE | 111 ms | 3072 KB |
sample-01.txt | AC | 5 ms | 3072 KB |
sample-02.txt | AC | 5 ms | 3072 KB |