Submission #2124618
Source Code Expand
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
//const int mod=(int)1e9+7;
const llint big=(llint)(2.19e15+1)*18;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
#define dme cout<<"-1\n";return 0
int main(void){
int n,i;cin>>n;
map<pair<int,int>,int>ban;
for(i=0;i<n;i++){
int a,b;cin>>a>>b;
if((i==0)^(a==0)){dme;}
if((i==1)^(b==0)){dme;}
ban[mp(a+b,a)]++;
}
//dpで解く
int ans=-2,sen=0;
pair<int,int>maebas=mp(-1,-1);
for(auto it:ban){
int a=it.fir.sec;
int b=it.fir.fir-a;
int kaz=it.sec;
if(kaz==0){continue;}
if(!(maebas.fir==it.fir.fir&&maebas.sec+1==it.fir.sec)){sen=0;}//前と連結してない
if(ban[mp(a-1+b-1,a-1)]>0){ans+=kaz;mineq(sen,kaz);}//接続あり
else{
ans+=kaz;ans+=max(0,kaz-sen);sen=kaz;
if(ban[mp(a-1+b,a-1)]+ban[mp(a+b,a-1)]==0&&a>0&&b>0){dme;}
if(ban[mp(a+b-1,a)]+ban[mp(a+b,a+1)]==0&&a>0&&b>0){dme;}
}
maebas=it.fir;
}
cout<<ans<<endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
A - Distance Pairs |
User |
WA_TLE |
Language |
C++14 (Clang 3.8.0) |
Score |
1500 |
Code Size |
2737 Byte |
Status |
AC |
Exec Time |
302 ms |
Memory |
14336 KB |
Judge Result
Set Name |
sample |
All |
Score / Max Score |
0 / 0 |
1500 / 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 |
190 ms |
5240 KB |
01-02.txt |
AC |
101 ms |
256 KB |
01-03.txt |
AC |
1 ms |
256 KB |
01-04.txt |
AC |
1 ms |
256 KB |
01-05.txt |
AC |
2 ms |
256 KB |
01-06.txt |
AC |
55 ms |
256 KB |
01-07.txt |
AC |
130 ms |
512 KB |
01-08.txt |
AC |
123 ms |
512 KB |
01-09.txt |
AC |
114 ms |
256 KB |
01-10.txt |
AC |
102 ms |
256 KB |
01-11.txt |
AC |
129 ms |
384 KB |
01-12.txt |
AC |
129 ms |
384 KB |
01-13.txt |
AC |
200 ms |
5760 KB |
01-14.txt |
AC |
302 ms |
14336 KB |
01-15.txt |
AC |
196 ms |
4992 KB |
01-16.txt |
AC |
92 ms |
256 KB |
01-17.txt |
AC |
91 ms |
256 KB |
01-18.txt |
AC |
91 ms |
256 KB |
01-19.txt |
AC |
228 ms |
9600 KB |
01-20.txt |
AC |
214 ms |
7040 KB |
01-21.txt |
AC |
218 ms |
7168 KB |
01-22.txt |
AC |
180 ms |
3712 KB |
01-23.txt |
AC |
124 ms |
512 KB |
01-24.txt |
AC |
123 ms |
512 KB |
01-25.txt |
AC |
1 ms |
256 KB |
01-26.txt |
AC |
1 ms |
256 KB |
01-27.txt |
AC |
72 ms |
384 KB |
01-28.txt |
AC |
57 ms |
512 KB |
01-29.txt |
AC |
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 |