Submission #996103
Source Code Expand
#include <vector> #include <cstdio> #include <algorithm> #include <map> using namespace std; int main() { int N; scanf("%d", &N); vector<pair<int, int> > A; for(int i=0; i<N; ++i) { int a, b; scanf("%d%d", &a, &b); A.emplace_back(a, b); } if(A[0].first!=0 || A[1].second!=0 || A[1].first!=A[0].second) { printf("-1\n"); return 0; } int ab = A[0].second; int sum = ab; { vector<int> vec(ab+1); for(auto & p : A) { if(p.first+p.second==ab) { ++vec[p.first]; } } if(vec[0]!=1 || vec[ab]!=1) { printf("-1\n"); return 0; } for(int i : vec) { if(i==0) { printf("-1\n"); return 0; } if(2<=i) { sum += (i-1)*2; } } } { vector<pair<int, int> > vec; for(auto & p : A) { if(p.first+p.second!=ab) { int aa = p.first+p.second - ab; int aaHalf = (aa+1)>>1; int aaa = p.first-aaHalf; if(aa<=0) { printf("-1\n"); return 0; } if(aa&1) { vec.emplace_back(p.first-aaHalf, aaHalf); ++sum; } vec.emplace_back(p.first-(aa>>1), aaHalf); ++sum; } } sort(vec.begin(), vec.end()); int beforeF = -1; int beforeS = 0; for(auto & p : vec) { if(p.first!=beforeF) { beforeF = p.first; beforeS = 0; } if(p.second!=beforeS && p.second!=beforeS+1) { printf("-1\n"); return 0; } beforeS = p.second; } } printf("%d\n", sum); return 0; }
Submission Info
Submission Time | |
---|---|
Task | A - Distance Pairs |
User | colun |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1471 Byte |
Status | WA |
Exec Time | 37 ms |
Memory | 3188 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:10:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &N); ^ ./Main.cpp:14:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d", &a, &b); ^
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 | 22 ms | 1400 KB |
01-02.txt | AC | 18 ms | 1400 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 | 16 ms | 1784 KB |
01-07.txt | WA | 31 ms | 2548 KB |
01-08.txt | WA | 32 ms | 3188 KB |
01-09.txt | WA | 31 ms | 3188 KB |
01-10.txt | WA | 28 ms | 3188 KB |
01-11.txt | AC | 28 ms | 2548 KB |
01-12.txt | AC | 28 ms | 2548 KB |
01-13.txt | AC | 31 ms | 2548 KB |
01-14.txt | AC | 22 ms | 1400 KB |
01-15.txt | AC | 32 ms | 2548 KB |
01-16.txt | AC | 21 ms | 2548 KB |
01-17.txt | AC | 17 ms | 1400 KB |
01-18.txt | AC | 26 ms | 3188 KB |
01-19.txt | WA | 30 ms | 2548 KB |
01-20.txt | WA | 34 ms | 2548 KB |
01-21.txt | WA | 34 ms | 2548 KB |
01-22.txt | WA | 37 ms | 3188 KB |
01-23.txt | AC | 34 ms | 3188 KB |
01-24.txt | AC | 30 ms | 2548 KB |
01-25.txt | AC | 18 ms | 1400 KB |
01-26.txt | AC | 18 ms | 1400 KB |
01-27.txt | AC | 18 ms | 1400 KB |
01-28.txt | AC | 18 ms | 1400 KB |
01-29.txt | AC | 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 |