Submission #995603


Source Code Expand

#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int A[SIZE],B[SIZE],cnt[2][SIZE];
VI d[SIZE];
void NO(){puts("-1");exit(0);}
int main(){
    DRI(N);
    REP(i,N)RII(A[i+1],B[i+1]);
    if(A[1]||B[2]||B[1]!=A[2]||A[2]==0)NO();
    int dd=A[2];
    int an=dd;
    int one=0;
    REPP(i,3,N+1){
        if(!A[i]||!B[i])NO();
        if(A[i]+B[i]==dd){
            cnt[0][A[i]]++;
            if(cnt[0][A[i]]>1)an+=2;
        }
        else if(A[i]+B[i]==dd+1){
            cnt[1][A[i]]++;
            if(cnt[1][A[i]]>1)an+=2;
            one=1;
        }
        else{
            an++;
            int p=A[i]+dd-B[i];
            if(p%2)NO();
            if(p/2<0||p/2>dd)NO();
            d[p/2].PB(A[i]-p/2);
        }
    }
    REPP(i,1,dd){
        if(!cnt[0][i])NO();
    }
    if(one){
        an+=dd+1;
        REPP(i,1,dd+1){
            if(!cnt[1][i])NO();
        }
    }
    REP(i,dd+1){
        int lt=0;
        sort(ALL(d[i]));
        REP(j,SZ(d[i])){
            if(d[i][j]!=lt&&d[i][j]!=lt+1)NO();
            lt=d[i][j];
        }
    }
    printf("%d\n",an);
    return 0;
}

Submission Info

Submission Time
Task A - Distance Pairs
User dreamoon
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2162 Byte
Status WA
Exec Time 51 ms
Memory 25600 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:34:11: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     DRI(N);
           ^
./Main.cpp:35:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     REP(i,N)RII(A[i+1],B[i+1]);
                               ^

Judge Result

Set Name sample All
Score / Max Score 0 / 0 0 / 1500
Status
AC × 2
AC × 24
WA × 9
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 43 ms 24448 KB
01-02.txt AC 39 ms 24448 KB
01-03.txt AC 26 ms 23680 KB
01-04.txt AC 23 ms 23680 KB
01-05.txt AC 23 ms 23680 KB
01-06.txt WA 33 ms 24192 KB
01-07.txt WA 38 ms 24448 KB
01-08.txt WA 40 ms 24448 KB
01-09.txt WA 37 ms 24448 KB
01-10.txt WA 37 ms 24448 KB
01-11.txt AC 45 ms 24960 KB
01-12.txt AC 46 ms 25064 KB
01-13.txt AC 50 ms 25084 KB
01-14.txt AC 44 ms 24832 KB
01-15.txt AC 51 ms 25084 KB
01-16.txt AC 42 ms 25084 KB
01-17.txt AC 39 ms 24448 KB
01-18.txt AC 39 ms 24448 KB
01-19.txt WA 49 ms 25600 KB
01-20.txt WA 43 ms 24448 KB
01-21.txt WA 43 ms 24448 KB
01-22.txt WA 42 ms 24448 KB
01-23.txt AC 37 ms 24448 KB
01-24.txt AC 40 ms 24448 KB
01-25.txt AC 40 ms 24448 KB
01-26.txt AC 40 ms 24448 KB
01-27.txt AC 40 ms 24448 KB
01-28.txt AC 38 ms 24448 KB
01-29.txt AC 26 ms 23680 KB
01-30.txt AC 23 ms 23680 KB
01-31.txt AC 26 ms 23680 KB
sample-01.txt AC 26 ms 23680 KB
sample-02.txt AC 26 ms 23680 KB