답안 #118438

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118438 2019-06-19T03:25:05 Z str0ct 화살표 그리기 (KOI18_arrowH) C++14
100 / 100
41 ms 4984 KB
#include<bits/stdc++.h>
using namespace std;
long long color[101010],opt[101010],sum;
typedef struct{
    long long ipt,w;
}nd;
bool operator<(nd a,nd b){
    return a.w<b.w;
}
nd arr[101010];
int main(){
    int N;
    scanf("%d",&N);
    for(int i=0;i<N;i++)
        scanf("%lld%lld",&arr[i].w,&arr[i].ipt);
    sort(arr,arr+N);
    memset(color,-1,sizeof(color));
    for(int i=0;i<N;i++){
        if(color[arr[i].ipt]!=-1)
            opt[i]=arr[i].w-color[arr[i].ipt];
        color[arr[i].ipt]=arr[i].w;
    }
    memset(color,-1,sizeof(color));
    for(int i=N-1;i>=0;i--){
        if(color[arr[i].ipt]!=-1&&(opt[i]==0||opt[i]>color[arr[i].ipt]-arr[i].w))
            opt[i]=color[arr[i].ipt]-arr[i].w;
        color[arr[i].ipt]=arr[i].w;
    }
    for(int i=0;i<N;i++)
        sum+=opt[i];
    printf("%lld",sum);
}

Compilation message

arrow.cpp: In function 'int main()':
arrow.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&N);
     ~~~~~^~~~~~~~~
arrow.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld",&arr[i].w,&arr[i].ipt);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1152 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 3 ms 1152 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 2 ms 1152 KB Output is correct
6 Correct 3 ms 1152 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 3 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1152 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 3 ms 1152 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 2 ms 1152 KB Output is correct
6 Correct 3 ms 1152 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 3 ms 1152 KB Output is correct
9 Correct 3 ms 1152 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 3 ms 1152 KB Output is correct
13 Correct 4 ms 1188 KB Output is correct
14 Correct 2 ms 1152 KB Output is correct
15 Correct 3 ms 1152 KB Output is correct
16 Correct 4 ms 1148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1152 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 3 ms 1152 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 2 ms 1152 KB Output is correct
6 Correct 3 ms 1152 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 3 ms 1152 KB Output is correct
9 Correct 3 ms 1152 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 3 ms 1152 KB Output is correct
13 Correct 4 ms 1188 KB Output is correct
14 Correct 2 ms 1152 KB Output is correct
15 Correct 3 ms 1152 KB Output is correct
16 Correct 4 ms 1148 KB Output is correct
17 Correct 7 ms 1408 KB Output is correct
18 Correct 7 ms 1476 KB Output is correct
19 Correct 5 ms 1408 KB Output is correct
20 Correct 6 ms 1536 KB Output is correct
21 Correct 5 ms 1408 KB Output is correct
22 Correct 5 ms 1408 KB Output is correct
23 Correct 5 ms 1408 KB Output is correct
24 Correct 5 ms 1408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1152 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 3 ms 1152 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 2 ms 1152 KB Output is correct
6 Correct 3 ms 1152 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 3 ms 1152 KB Output is correct
9 Correct 3 ms 1152 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 3 ms 1152 KB Output is correct
12 Correct 3 ms 1152 KB Output is correct
13 Correct 4 ms 1188 KB Output is correct
14 Correct 2 ms 1152 KB Output is correct
15 Correct 3 ms 1152 KB Output is correct
16 Correct 4 ms 1148 KB Output is correct
17 Correct 7 ms 1408 KB Output is correct
18 Correct 7 ms 1476 KB Output is correct
19 Correct 5 ms 1408 KB Output is correct
20 Correct 6 ms 1536 KB Output is correct
21 Correct 5 ms 1408 KB Output is correct
22 Correct 5 ms 1408 KB Output is correct
23 Correct 5 ms 1408 KB Output is correct
24 Correct 5 ms 1408 KB Output is correct
25 Correct 35 ms 4984 KB Output is correct
26 Correct 33 ms 4600 KB Output is correct
27 Correct 34 ms 4856 KB Output is correct
28 Correct 31 ms 4480 KB Output is correct
29 Correct 35 ms 4984 KB Output is correct
30 Correct 29 ms 4196 KB Output is correct
31 Correct 41 ms 4728 KB Output is correct
32 Correct 34 ms 4600 KB Output is correct