Submission #1053865
Source Code Expand
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #include <unordered_map> #include <cstring> #include <ctime> #include <set> #include <map> using namespace std; typedef long long ll; const int maxn = 100005; int n; pair<int,int> a[maxn]; bool check_1(){ if(a[1].first!=0||a[2].second!=0||a[2].first!=a[1].second)return false; for(int i=3;i<=n;i++) if(a[i].first==0||a[i].second==0)return false; set<pair<int,int>>st; for(int i=1;i<=n;i++)st.insert(a[i]); for(int i=3;i<=n;i++){ int cnt=0; for(int j=-1;j<=1;j++) if(st.find(make_pair(a[i].first-1,a[i].second+j))!=st.end()){ cnt++; break; } for(int j=-1;j<=1;j++) if(st.find(make_pair(a[i].first+j,a[i].second-1))!=st.end()){ cnt++; break; } if(cnt<2)return false; } return true; } bool cmp(pair<int,int> a,pair<int,int> b){ int ta = a.first + a.second; int tb = b.first + b.second; return ta == tb ? a.first < b.first: ta < tb; } int cal(){ int ret=0; sort(a+1,a+n+1,cmp); map<pair<int,int>,int>mp; for(int i=1;i<=n;i++){ int pos = i; for(int j=i;j<=n;j++){ if(a[j]!=a[i])break; pos=j; } if(mp.find(make_pair(a[i].first -1,a[i].second-1))!=mp.end()){ ret+=mp[make_pair(a[i].first-1,a[i].second-1)]; mp[a[i]] = 0; } else { int tmp =0; if(mp.find(make_pair(a[i].first-1,a[i].second+1))!=mp.end()){ tmp = mp[make_pair(a[i].first-1,a[i].second+1)]; } int cur = min(tmp, pos - i +1); ret+=cur; mp[a[i]] = pos-i+1; } i =pos; } return ret; } int main() { // freopen("in.cpp","r",stdin); cin>>n; for(int i=1; i<=n; i++) { int x,y; cin>>x>>y; a[i].first = x; a[i].second = y; } if(!check_1()){ cout<<-1<<endl; return 0; } cout<<2*n-2-cal()<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | A - Distance Pairs |
User | suiyuan2009 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2020 Byte |
Status | WA |
Exec Time | 262 ms |
Memory | 7296 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 | 89 ms | 5760 KB |
01-02.txt | AC | 39 ms | 1024 KB |
01-03.txt | AC | 3 ms | 256 KB |
01-04.txt | AC | 3 ms | 256 KB |
01-05.txt | WA | 3 ms | 256 KB |
01-06.txt | WA | 28 ms | 640 KB |
01-07.txt | WA | 84 ms | 1280 KB |
01-08.txt | WA | 78 ms | 1280 KB |
01-09.txt | WA | 63 ms | 1152 KB |
01-10.txt | WA | 51 ms | 1024 KB |
01-11.txt | WA | 75 ms | 1152 KB |
01-12.txt | WA | 72 ms | 1152 KB |
01-13.txt | WA | 192 ms | 7296 KB |
01-14.txt | AC | 262 ms | 7296 KB |
01-15.txt | WA | 208 ms | 7296 KB |
01-16.txt | WA | 40 ms | 1024 KB |
01-17.txt | AC | 43 ms | 1024 KB |
01-18.txt | AC | 41 ms | 1024 KB |
01-19.txt | WA | 210 ms | 7296 KB |
01-20.txt | WA | 182 ms | 6016 KB |
01-21.txt | WA | 186 ms | 6144 KB |
01-22.txt | WA | 142 ms | 3712 KB |
01-23.txt | AC | 58 ms | 1280 KB |
01-24.txt | AC | 64 ms | 1280 KB |
01-25.txt | AC | 40 ms | 1024 KB |
01-26.txt | AC | 40 ms | 1024 KB |
01-27.txt | AC | 39 ms | 1024 KB |
01-28.txt | AC | 40 ms | 1024 KB |
01-29.txt | WA | 3 ms | 256 KB |
01-30.txt | AC | 3 ms | 256 KB |
01-31.txt | AC | 3 ms | 256 KB |
sample-01.txt | AC | 3 ms | 256 KB |
sample-02.txt | AC | 3 ms | 256 KB |