Submission #995597
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
int N;
int A[101010],B[101010];
int L;
int did[101010];
int ok[101010];
set<pair<int,int>> S;
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N;
FOR(i,N) cin>>A[i]>>B[i];
if(A[0]!=0) return _P("-1\n");
if(B[1]!=0) return _P("-1\n");
if(A[1]!=B[0]) return _P("-1\n");
L=A[1];
ok[0]=ok[L]=1;
did[0]=did[1]=1;
S.insert({0,L});
S.insert({L,0});
vector<pair<int,int>> V;
int ret=1;
for(i=2;i<N;i++) {
if(A[i]==0 || B[i]==0) return _P("-1\n");
if(A[i]+B[i]<L) return _P("-1\n");
if(A[i]+B[i]==L) {
did[i]=1;
if(ok[A[i]]==1) ret++;
ok[A[i]]=1;
ret++;
S.insert({A[i],B[i]});
}
else {
V.push_back({A[i]+B[i],i});
}
}
FOR(i,L+1) if(ok[i]==0) return _P("-1\n");
sort(ALL(V));
FORR(r,V) {
x = r.second;
if(S.count({A[x]-1,B[x]-1})) {
ret++;
}
else if(S.count({A[x]-1,B[x]}) && S.count({A[x],B[x]-1})) {
ret+=2;
}
else {
return _P("-1\n");
}
S.insert({A[x],B[x]});
}
assert(0);
_P("%d\n",ret);
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n';
FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
solve(); return 0;
}
Submission Info
Submission Time |
|
Task |
A - Distance Pairs |
User |
kmjp |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1714 Byte |
Status |
WA |
Exec Time |
174 ms |
Memory |
6900 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 |
18 ms |
1024 KB |
01-02.txt |
AC |
14 ms |
1024 KB |
01-03.txt |
RE |
109 ms |
256 KB |
01-04.txt |
RE |
107 ms |
256 KB |
01-05.txt |
RE |
106 ms |
256 KB |
01-06.txt |
RE |
121 ms |
1404 KB |
01-07.txt |
WA |
27 ms |
2424 KB |
01-08.txt |
WA |
26 ms |
2424 KB |
01-09.txt |
WA |
25 ms |
2296 KB |
01-10.txt |
RE |
134 ms |
2296 KB |
01-11.txt |
RE |
141 ms |
2424 KB |
01-12.txt |
RE |
141 ms |
2424 KB |
01-13.txt |
RE |
164 ms |
6900 KB |
01-14.txt |
RE |
155 ms |
6528 KB |
01-15.txt |
RE |
174 ms |
6516 KB |
01-16.txt |
RE |
127 ms |
2168 KB |
01-17.txt |
RE |
122 ms |
1408 KB |
01-18.txt |
RE |
128 ms |
2168 KB |
01-19.txt |
WA |
47 ms |
5620 KB |
01-20.txt |
RE |
172 ms |
5876 KB |
01-21.txt |
RE |
174 ms |
6004 KB |
01-22.txt |
RE |
172 ms |
4212 KB |
01-23.txt |
AC |
27 ms |
2424 KB |
01-24.txt |
AC |
26 ms |
2296 KB |
01-25.txt |
AC |
15 ms |
1024 KB |
01-26.txt |
AC |
15 ms |
1024 KB |
01-27.txt |
AC |
16 ms |
1788 KB |
01-28.txt |
AC |
17 ms |
1788 KB |
01-29.txt |
RE |
107 ms |
256 KB |
01-30.txt |
AC |
2 ms |
256 KB |
01-31.txt |
AC |
2 ms |
256 KB |
sample-01.txt |
RE |
106 ms |
256 KB |
sample-02.txt |
AC |
2 ms |
256 KB |