Submission #1053250
Source Code Expand
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #include <unordered_map> #include <cstring> #include <ctime> #include <set> using namespace std; typedef long long ll; const int maxn = 100005; set<pair<int,int>> st; pair<int,int> a[maxn]; bool vis[maxn]; int n; bool cmp(pair<int,int>a,pair<int,int>b) { return a.first + a.second == b.first + b.second ? a.first < b.first : a.first + a.second < b.first + b.second; } bool check_1() { if(a[1].first!=0||a[2].second!=0||a[1].second!=a[2].first)return false; for(int i=3;i<=n;i++) if(a[i].first==0||a[i].second==0)return false; return true; } bool check_2(int&ret) { if(n>2)sort(a+3,a+n+1, cmp); if(a[1].second==0)return false; vis[1] = vis[2] = 1; st.insert(a[1]); st.insert(a[2]); ret += a[1].second; if(a[1].second==1) return true; int cnt = 0; for(int i=3; i<=n; i++) { if(a[i].first + a[i].second != a[1].second) continue; if(st.find(a[i])!=st.end())continue; st.insert(a[i]); vis[i] = 1; cnt++; } return cnt == a[1].second - 1; } bool pd(int x,int y) { int x1 = x - 1, y1, x2, y2 = y - 1; for(int y1 = y-1; y1<=y+1; y1++) for(int x2=x-1; x2<=x+1; x2++) { if(st.find(make_pair(x1,y1))==st.end())continue; if(st.find(make_pair(x2,y2))==st.end())continue; return true; } return false; } bool check_3(int&ret) { for(int i=3; i<=n; i++) { /*if(vis[i])continue; pair<int,int> fa = make_pair(a[i].first-1,a[i].second-1); if(st.find(fa)!=st.end()) { vis[i]=1; ret++; st.insert(a[i]); } else { if(pd(a[i].first,a[i].second)) { vis[i] = 1; ret+=2; st.insert(a[i]); } else return false; }*/ int pos = i; for(int j=i;j<=n;j++) { if(a[j].first + a[j].second != a[i].first + a[i].second)break; pos = j; } for(int j=i;j<=pos;j++) { if(vis[j]) continue; if(st.find(make_pair(a[j].first-1,a[j].second-1))!=st.end()) { vis[j] =1; ret++; st.insert(a[j]); } } for(int j=i;j<=pos;j++){ if(vis[j])continue; if(pd(a[j].first,a[j].second)){ vis[j] =1; ret+=2; st.insert(a[j]); } } for(int j = i;j<=pos;j++) { if(vis[j])continue; if(st.find(make_pair(a[j].first-1,a[j].second+1))!=st.end()&&st.find(make_pair(a[j].first+1,a[j].second-1))!=st.end()){ vis[j]=1; ret+=2; st.insert(a[j]); } else return false; } i = pos; } return true; } 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; } int ret = 0; if(!check_1()) { cout<<-1<<endl; return 0; } if(!check_2(ret)) { cout<<-1<<endl; return 0; } if(!check_3(ret)) { cout<<-1<<endl; return 0; } cout<<ret<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | A - Distance Pairs |
User | suiyuan2009 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 3442 Byte |
Status | WA |
Exec Time | 118 ms |
Memory | 5760 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 | 77 ms | 1024 KB |
01-02.txt | AC | 67 ms | 1152 KB |
01-03.txt | AC | 2 ms | 384 KB |
01-04.txt | AC | 2 ms | 256 KB |
01-05.txt | AC | 3 ms | 256 KB |
01-06.txt | WA | 32 ms | 768 KB |
01-07.txt | WA | 64 ms | 1024 KB |
01-08.txt | WA | 61 ms | 1024 KB |
01-09.txt | WA | 58 ms | 1024 KB |
01-10.txt | WA | 57 ms | 1152 KB |
01-11.txt | AC | 68 ms | 1280 KB |
01-12.txt | AC | 68 ms | 1152 KB |
01-13.txt | AC | 107 ms | 5760 KB |
01-14.txt | AC | 113 ms | 5760 KB |
01-15.txt | AC | 117 ms | 5760 KB |
01-16.txt | AC | 49 ms | 1152 KB |
01-17.txt | AC | 59 ms | 1152 KB |
01-18.txt | AC | 54 ms | 1152 KB |
01-19.txt | WA | 118 ms | 4608 KB |
01-20.txt | WA | 109 ms | 4864 KB |
01-21.txt | WA | 109 ms | 4992 KB |
01-22.txt | WA | 97 ms | 3200 KB |
01-23.txt | AC | 62 ms | 1024 KB |
01-24.txt | AC | 60 ms | 1024 KB |
01-25.txt | AC | 49 ms | 1024 KB |
01-26.txt | AC | 50 ms | 1024 KB |
01-27.txt | AC | 48 ms | 1024 KB |
01-28.txt | AC | 51 ms | 1024 KB |
01-29.txt | AC | 3 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 |