Submission #2623158
Source Code Expand
#include <bits/stdc++.h> #include <unistd.h> #define ll long long #define inf 1000000007 #define inf16 0x3f3f3f3f #define INF 1000000000000000007LL #define VI vector<int> #define VPII vector<pair<int, int> > #define VLL vector<ll> #define PII pair<int, int> #define st first #define nd second #define pb push_back #define mp make_pair #define eb emplace_back #define endl '\n' #define ALL(c) (c).begin(), (c).end() using namespace std; const int N = 1e5+7; int n, ans; int A[N]; int B[N]; PII mB[N]; //maksymalne B dla danego A PII mA[N]; //maksymalne A dla danego B map<PII, int> takie; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> n; for(int i = 1; i <= n; ++i) { cin >> A[i] >> B[i]; takie[{A[i], B[i]}] = i; mB[A[i]] = max(mB[A[i]], mp(B[i], i)); mA[B[i]] = max(mA[B[i]], mp(A[i], i)); } if(A[2]!=B[1] || A[1] || B[2]) { cout << -1 << endl; return 0; } if(A[2]==1) ++ans; for(int i = 3; i <= n; ++i) { if(takie.find({A[i]-1, B[i]-1})!=takie.end()) ++ans; else { if(mB[A[i]-1].st>B[i]-1 && mA[B[i]-1].st>A[i]-1) ans += 2; else { cout << -1 << endl; return 0; } } } cout << ans << endl; }
Submission Info
Submission Time | |
---|---|
Task | A - Distance Pairs |
User | shadowatyy |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1261 Byte |
Status | WA |
Exec Time | 89 ms |
Memory | 8960 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, sample-01.txt, sample-02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 58 ms | 8960 KB |
01-02.txt | AC | 17 ms | 1024 KB |
01-03.txt | AC | 1 ms | 256 KB |
01-04.txt | AC | 1 ms | 256 KB |
01-05.txt | WA | 1 ms | 256 KB |
01-06.txt | WA | 10 ms | 768 KB |
01-07.txt | WA | 32 ms | 1280 KB |
01-08.txt | WA | 34 ms | 1408 KB |
01-09.txt | WA | 24 ms | 1152 KB |
01-10.txt | WA | 18 ms | 1024 KB |
01-11.txt | WA | 29 ms | 1152 KB |
01-12.txt | WA | 27 ms | 1152 KB |
01-13.txt | WA | 86 ms | 8192 KB |
01-14.txt | WA | 89 ms | 8832 KB |
01-15.txt | AC | 79 ms | 8832 KB |
01-16.txt | AC | 14 ms | 1024 KB |
01-17.txt | AC | 14 ms | 1024 KB |
01-18.txt | AC | 14 ms | 1024 KB |
01-19.txt | WA | 82 ms | 8064 KB |
01-20.txt | WA | 74 ms | 6528 KB |
01-21.txt | WA | 76 ms | 6528 KB |
01-22.txt | WA | 61 ms | 3968 KB |
01-23.txt | WA | 34 ms | 1408 KB |
01-24.txt | AC | 32 ms | 1408 KB |
01-25.txt | AC | 23 ms | 1280 KB |
01-26.txt | AC | 24 ms | 1280 KB |
01-27.txt | AC | 28 ms | 1280 KB |
01-28.txt | AC | 29 ms | 1408 KB |
01-29.txt | WA | 1 ms | 256 KB |
01-30.txt | AC | 1 ms | 256 KB |
01-31.txt | AC | 1 ms | 256 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |