Submission #1053129
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 check_1() { if(a[1].first!=0||a[2].second!=0||a[1].second!=a[2].first)return false; return true; } bool check_2(int&ret) { if(n>2)sort(a+3,a+n+1); 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) { for(int x1=x-1; x1<=x+1; x1++) for(int y1=y-1; y1<=y+1; y1++) { if(st.find(make_pair(x1,y1))==st.end())continue; for(int x2=x-1; x2<=x+1; x2++) for(int y2=y-1; y2<=y+1; y2++) { if(min(x1,x2)+1!=x||min(y1,y2)+1!=y)continue; if(st.find(make_pair(x2,y2))==st.end())continue; //cout<<x1<<" "<<y1<<","<<x2<<" "<<y2<<endl; 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; } } 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 | 2452 Byte |
Status | WA |
Exec Time | 107 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 | 74 ms | 1024 KB |
01-02.txt | AC | 50 ms | 1024 KB |
01-03.txt | AC | 3 ms | 256 KB |
01-04.txt | AC | 3 ms | 256 KB |
01-05.txt | AC | 3 ms | 256 KB |
01-06.txt | WA | 30 ms | 768 KB |
01-07.txt | WA | 60 ms | 1152 KB |
01-08.txt | WA | 58 ms | 1152 KB |
01-09.txt | WA | 55 ms | 1024 KB |
01-10.txt | WA | 55 ms | 1152 KB |
01-11.txt | AC | 65 ms | 1280 KB |
01-12.txt | AC | 65 ms | 1152 KB |
01-13.txt | AC | 104 ms | 5760 KB |
01-14.txt | AC | 107 ms | 5760 KB |
01-15.txt | AC | 107 ms | 5760 KB |
01-16.txt | AC | 47 ms | 1152 KB |
01-17.txt | AC | 53 ms | 1152 KB |
01-18.txt | AC | 50 ms | 1152 KB |
01-19.txt | WA | 84 ms | 3456 KB |
01-20.txt | WA | 98 ms | 4864 KB |
01-21.txt | WA | 100 ms | 4992 KB |
01-22.txt | WA | 89 ms | 3200 KB |
01-23.txt | AC | 57 ms | 1152 KB |
01-24.txt | AC | 57 ms | 1024 KB |
01-25.txt | AC | 50 ms | 1024 KB |
01-26.txt | AC | 50 ms | 1024 KB |
01-27.txt | AC | 56 ms | 1024 KB |
01-28.txt | AC | 57 ms | 1024 KB |
01-29.txt | AC | 2 ms | 256 KB |
01-30.txt | AC | 2 ms | 256 KB |
01-31.txt | AC | 2 ms | 256 KB |
sample-01.txt | AC | 3 ms | 256 KB |
sample-02.txt | AC | 2 ms | 256 KB |