Submission #20240

#TimeUsernameProblemLanguageResultExecution timeMemory
20240baneling100Palembang Bridges (APIO15_bridge)C++98
0 / 100
0 ms2676 KiB
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#define N_MAX 100000

using namespace std;

int K, N, A[(N_MAX<<1)+1];
int M, Left[N_MAX+1], Right[N_MAX+1];
long long Ans;

int main(void) {

    int i, x, y;
    char t1, t2;

    scanf("%d %d ",&K,&N);
    for(i=1 ; i<=N ; i++) {
        scanf("%c %d %c %d ",&t1,&x,&t2,&y);
        if(t1==t2) Ans+=abs(x-y);
        else {
            Left[++M]=min(x,y);
            Right[ M]=max(x,y);
        }
    }
    if(K==1) {
        for(i=1 ; i<=M ; i++) {
            A[2*i-1]=Left[i];
            A[2*i  ]=Right[i];
        }
        sort(A+1,A+(M<<1)+1);
        for(i=1 ; i<=M ; i++)
            Ans+=(long long)abs(A[M]-Left[i])+abs(A[M]-Right[i])+1;
        printf("%d",Ans);
    }
    else {
    }

    return 0;
}

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:34:24: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
         printf("%d",Ans);
                        ^
bridge.cpp:17:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d ",&K,&N);
                          ^
bridge.cpp:19:44: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%c %d %c %d ",&t1,&x,&t2,&y);
                                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...